Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Preserve "Invariant Violation" name
  • Loading branch information
gaearon committed Jun 19, 2018
1 parent 07d1b47 commit d6c9c5c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion checkPropTypes.js
Expand Up @@ -50,10 +50,12 @@ function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
// This is intentionally an invariant that gets caught. It's the same
// behavior as without this statement except with a better message.
if (typeof typeSpecs[typeSpecName] !== 'function') {
throw new Error(
var err = Error(
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
);
err.name = 'Invariant Violation';
throw err;
}
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
} catch (ex) {
Expand Down
4 changes: 3 additions & 1 deletion factoryWithThrowingShims.js
Expand Up @@ -17,11 +17,13 @@ module.exports = function() {
// It is still safe when called from React.
return;
}
throw new Error(
var err = new Error(
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
'Use PropTypes.checkPropTypes() to call them. ' +
'Read more at http://fb.me/use-check-prop-types'
);
err.name = 'Invariant Violation';
throw err;
};
shim.isRequired = shim;
function getShim() {
Expand Down
4 changes: 3 additions & 1 deletion factoryWithTypeCheckers.js
Expand Up @@ -175,11 +175,13 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
if (secret !== ReactPropTypesSecret) {
if (throwOnDirectAccess) {
// New behavior only for users of `prop-types` package
throw new Error(
var err = new Error(
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
'Use `PropTypes.checkPropTypes()` to call them. ' +
'Read more at http://fb.me/use-check-prop-types'
);
err.name = 'Invariant Violation';
throw err;
} else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
// Old behavior for people using React.PropTypes
var cacheKey = componentName + ':' + propName;
Expand Down

0 comments on commit d6c9c5c

Please sign in to comment.