Inline internal error message

So that it is stripped out by the error code transform
This commit is contained in:
Andrew Clark
2017-02-06 15:43:47 -08:00
parent 5b9a6d075c
commit 661f04746e
7 changed files with 67 additions and 86 deletions
@@ -72,9 +72,6 @@ const {
Deletion,
} = ReactTypeOfSideEffect;
const internalErrorMessage =
'This error is likely caused by a bug in React. Please file an issue.';
function coerceRef(current: ?Fiber, element: ReactElement) {
let mixedRef = element.ref;
if (mixedRef != null && typeof mixedRef !== 'function') {
@@ -92,9 +89,10 @@ function coerceRef(current: ?Fiber, element: ReactElement) {
}
}
invariant(
inst, 'Missing owner for string ref %s. (%s)',
mixedRef,
internalErrorMessage
inst,
'Missing owner for string ref %s. This error is likely caused by a ' +
'bug in React. Please file an issue.',
mixedRef
);
const stringRef = String(mixedRef);
// Check if previous string ref matches new string ref
@@ -806,8 +804,8 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
const iteratorFn = getIteratorFn(newChildrenIterable);
invariant(
typeof iteratorFn === 'function',
'An object is not an iterable. (%s)',
internalErrorMessage
'An object is not an iterable. This error is likely caused by a bug in ' +
'React. Please file an issue.'
);
if (__DEV__) {
@@ -71,9 +71,6 @@ if (__DEV__) {
var warnedAboutStatelessRefs = {};
}
const internalErrorMessage =
'This error is likely caused by a bug in React. Please file an issue.';
module.exports = function<T, P, I, TI, PI, C, CX, PL>(
config : HostConfig<T, P, I, TI, PI, C, CX, PL>,
hostContext : HostContext<C, CX>,
@@ -347,8 +344,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
nextProps = memoizedProps;
invariant(
nextProps !== null,
'We should always have pending or current props. (%s)',
internalErrorMessage
'We should always have pending or current props. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
}
} else if (nextProps === null || memoizedProps === nextProps) {
@@ -450,8 +447,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
function mountIndeterminateComponent(current, workInProgress, priorityLevel) {
invariant(
current === null,
'An indeterminate component should never have mounted. (%s)',
internalErrorMessage
'An indeterminate component should never have mounted. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
var fn = workInProgress.type;
var props = workInProgress.pendingProps;
@@ -521,8 +518,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
nextCoroutine = current && current.memoizedProps;
invariant(
nextCoroutine != null,
'We should always have pending or current props. (%s)',
internalErrorMessage
'We should always have pending or current props. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
}
} else if (nextCoroutine === null || workInProgress.memoizedProps === nextCoroutine) {
@@ -587,8 +584,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
nextChildren = current && current.memoizedProps;
invariant(
nextChildren != null,
'We should always have pending or current props. (%s)',
internalErrorMessage
'We should always have pending or current props. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
}
} else if (nextChildren === null || workInProgress.memoizedProps === nextChildren) {
@@ -741,8 +738,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
default:
invariant(
false,
'Unknown unit of work tag. (%s)',
internalErrorMessage
'Unknown unit of work tag. This error is likely caused by a bug in ' +
'React. Please file an issue.'
);
}
}
@@ -751,8 +748,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
invariant(
workInProgress.tag === ClassComponent ||
workInProgress.tag === HostRoot,
'Invalid type of work. (%s)',
internalErrorMessage
'Invalid type of work. This error is likely caused by a bug in React. ' +
'Please file an issue.'
);
// Add an error effect so we can handle the error during the commit phase
@@ -40,9 +40,6 @@ var invariant = require('invariant');
const isArray = Array.isArray;
const internalErrorMessage =
'This error is likely caused by a bug in React. Please file an issue.';
module.exports = function(
scheduleUpdate : (fiber : Fiber, priorityLevel : PriorityLevel) => void,
getPriorityContext : () => PriorityLevel,
@@ -262,8 +259,8 @@ module.exports = function(
let props = workInProgress.pendingProps;
invariant(
props,
'There must be pending props for an initial mount. (%s)',
internalErrorMessage
'There must be pending props for an initial mount. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
const unmaskedContext = getUnmaskedContext(workInProgress);
@@ -305,8 +302,8 @@ module.exports = function(
newProps = workInProgress.memoizedProps;
invariant(
newProps != null,
'There should always be pending or memoized props. (%s)',
internalErrorMessage
'There should always be pending or memoized props. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
}
const newUnmaskedContext = getUnmaskedContext(workInProgress);
@@ -372,8 +369,8 @@ module.exports = function(
newProps = oldProps;
invariant(
newProps != null,
'There should always be pending or memoized props. (%s)',
internalErrorMessage
'There should always be pending or memoized props. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
}
const oldContext = instance.context;
@@ -36,9 +36,6 @@ var {
var invariant = require('invariant');
const internalErrorMessage =
'This error is likely caused by a bug in React. Please file an issue.';
module.exports = function<T, P, I, TI, PI, C, CX, PL>(
config : HostConfig<T, P, I, TI, PI, C, CX, PL>,
captureError : (failedFiber : Fiber, error: Error) => ?Fiber
@@ -101,8 +98,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
invariant(
false,
'Expected to find a host parent. (%s)',
internalErrorMessage
'Expected to find a host parent. This error is likely caused by a bug ' +
'in React. Please file an issue.'
);
}
@@ -116,8 +113,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
invariant(
false,
'Expected to find a host parent. (%s)',
internalErrorMessage
'Expected to find a host parent. This error is likely caused by a bug ' +
'in React. Please file an issue.'
);
}
@@ -188,8 +185,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
default:
invariant(
false,
'Invalid host parent fiber. (%s)',
internalErrorMessage
'Invalid host parent fiber. This error is likely caused by a bug ' +
'in React. Please file an issue.'
);
}
if (parentFiber.effectTag & ContentReset) {
@@ -393,8 +390,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
case HostText: {
invariant(
finishedWork.stateNode !== null && current != null,
'This should only be done during updates. (%s)',
internalErrorMessage
'This should only be done during updates. This error is likely ' +
'caused by a bug in React. Please file an issue.'
);
const textInstance : TI = finishedWork.stateNode;
const newText : string = finishedWork.memoizedProps;
@@ -411,8 +408,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
default: {
invariant(
false,
'This unit of work tag should not have side-effects. (%s)',
internalErrorMessage
'This unit of work tag should not have side-effects. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
}
}
@@ -477,8 +474,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
default: {
invariant(
false,
'This unit of work tag should not have side-effects. (%s)',
internalErrorMessage
'This unit of work tag should not have side-effects. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
}
}
@@ -48,9 +48,6 @@ if (__DEV__) {
var invariant = require('invariant');
const internalErrorMessage =
'This error is likely caused by a bug in React. Please file an issue.';
module.exports = function<T, P, I, TI, PI, C, CX, PL>(
config : HostConfig<T, P, I, TI, PI, C, CX, PL>,
hostContext : HostContext<C, CX>,
@@ -122,8 +119,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
var coroutine = (workInProgress.memoizedProps : ?ReactCoroutine);
invariant(
coroutine,
'Should be resolved by now. (%s)',
internalErrorMessage
'Should be resolved by now. This error is likely caused by a bug in ' +
'React. Please file an issue.',
);
// First step of the coroutine has completed. Now we need to do the second.
@@ -241,8 +238,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
if (!newProps) {
invariant(
workInProgress.stateNode !== null,
'We must have new props for new mounts. (%s)',
internalErrorMessage
'We must have new props for new mounts. This error is likely ' +
'caused by a bug in React. Please file an issue.'
);
// This can happen when we abort work.
return null;
@@ -291,8 +288,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
if (typeof newText !== 'string') {
invariant(
workInProgress.stateNode !== null,
'We must have new props for new mounts. (%s)',
internalErrorMessage
'We must have new props for new mounts. This error is likely ' +
'caused by a bug in React. Please file an issue.'
);
// This can happen when we abort work.
return null;
@@ -325,15 +322,16 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
case IndeterminateComponent:
invariant(
false,
'An indeterminate component should have become determinate before completing. (%s)',
internalErrorMessage
'An indeterminate component should have become determinate before ' +
'completing. This error is likely caused by a bug in React. Please ' +
'file an issue.'
);
// eslint-disable-next-line no-fallthrough
default:
invariant(
false,
'Unknown unit of work tag. (%s)',
internalErrorMessage
'Unknown unit of work tag. This error is likely caused by a bug in ' +
'React. Please file an issue.'
);
}
}
@@ -36,9 +36,6 @@ export type HostContext<C, CX> = {
resetHostContainer() : void,
};
const internalErrorMessage =
'This error is likely caused by a bug in React. Please file an issue.';
module.exports = function<T, P, I, TI, PI, C, CX, PL>(
config : HostConfig<T, P, I, TI, PI, C, CX, PL>
) : HostContext<C, CX> {
@@ -55,8 +52,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
const rootInstance = rootInstanceStackCursor.current;
invariant(
rootInstance != null,
'Expected root container to exist. (%s)',
internalErrorMessage
'Expected root container to exist. This error is likely caused by a ' +
'bug in React. Please file an issue.'
);
return rootInstance;
}
@@ -84,8 +81,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
const context = contextStackCursor.current;
invariant(
context != null,
'Expected host context to exist. (%s)',
internalErrorMessage
'Expected host context to exist. This error is likely caused by a bug ' +
'in React. Please file an issue.'
);
return context;
}
@@ -94,8 +91,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
const rootInstance = rootInstanceStackCursor.current;
invariant(
rootInstance != null,
'Expected root host context to exist. (%s)',
internalErrorMessage
'Expected root host context to exist. This error is likely caused by ' +
'a bug in React. Please file an issue.'
);
const context = contextStackCursor.current || emptyObject;
@@ -92,9 +92,6 @@ if (__DEV__) {
var timeHeuristicForUnitOfWork = 1;
const internalErrorMessage =
'This error is likely caused by a bug in React. Please file an issue.';
module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P, I, TI, PI, C, CX, PL>) {
const hostContext = ReactFiberHostContext(config);
const { popHostContainer, popHostContext, resetHostContainer } = hostContext;
@@ -348,8 +345,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
invariant(
root.current !== finishedWork,
'Cannot commit the same tree as before. This is probably a bug ' +
'related to the return field. (%s)',
internalErrorMessage
'related to the return field. This error is likely caused by a bug ' +
'in React. Please file an issue.'
);
// Updates that occur during the commit phase should have Task priority
@@ -385,8 +382,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
} catch (error) {
invariant(
nextEffect != null,
'Should have next effect. (%s)',
internalErrorMessage
'Should have next effect. This error is likely caused by a bug ' +
'in React. Please file an issue.'
);
captureError(nextEffect, error);
// Clean-up
@@ -415,8 +412,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
} catch (error) {
invariant(
nextEffect != null,
'Should have next effect. (%s)',
internalErrorMessage
'Should have next effect. This error is likely caused by a bug ' +
'in React. Please file an issue.'
);
captureError(nextEffect, error);
if (nextEffect) {
@@ -716,8 +713,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
function performWork(priorityLevel : PriorityLevel, deadline : Deadline | null) {
invariant(
!isPerformingWork,
'performWork was called recursively. (%s)',
internalErrorMessage
'performWork was called recursively. This error is likely caused ' +
'by a bug in React. Please file an issue.'
);
isPerformingWork = true;
const isPerformingDeferredWork = Boolean(deadline);
@@ -729,8 +726,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
while (priorityLevel !== NoWork && !fatalError) {
invariant(
deadline || (priorityLevel < HighPriority),
'Cannot perform deferred work without a deadline. (%s)',
internalErrorMessage
'Cannot perform deferred work without a deadline. This error is ' +
'likely caused by a bug in React. Please file an issue.'
);
// Before starting any work, check to see if there are any pending
@@ -1001,8 +998,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
invariant(
capturedError != null,
'No error for given unit of work. (%s)',
internalErrorMessage
'No error for given unit of work. This error is likely caused by a ' +
'bug in React. Please file an issue.'
);
let error;
@@ -1038,8 +1035,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
default:
invariant(
false,
'Invalid type of work. (%s)',
internalErrorMessage
'Invalid type of work. This error is likely caused by a bug in ' +
'React. Please file an issue.'
);
}
}