mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
make invariant show formatted actual errors in all unminified environments
Because we can have !__DEV__ but unminified, we still want to see the message in those cases.
This commit is contained in:
committed by
Paul O’Shannessy
parent
e8e08127c5
commit
559eb89965
Vendored
+23
-25
@@ -29,34 +29,32 @@
|
||||
* will remain to ensure logic does not differ in production.
|
||||
*/
|
||||
|
||||
var invariant = function(condition) {
|
||||
var invariant = function(condition, format, a, b, c, d, e, f) {
|
||||
if (__DEV__) {
|
||||
if (format === undefined) {
|
||||
throw new Error('invariant requires an error message argument');
|
||||
}
|
||||
}
|
||||
|
||||
if (!condition) {
|
||||
var error = new Error(
|
||||
'Minified exception occured; use the non-minified dev environment for ' +
|
||||
'the full error message and additional helpful warnings.'
|
||||
);
|
||||
error.framesToPop = 1;
|
||||
var error;
|
||||
if (format === undefined) {
|
||||
error = new Error(
|
||||
'Minified exception occurred; use the non-minified dev environment ' +
|
||||
'for the full error message and additional helpful warnings.'
|
||||
);
|
||||
} else {
|
||||
var args = [a, b, c, d, e, f];
|
||||
var argIndex = 0;
|
||||
error = new Error(
|
||||
'Invariant Violation: ' +
|
||||
format.replace(/%s/g, function() { return args[argIndex++]; })
|
||||
);
|
||||
}
|
||||
|
||||
error.framesToPop = 1; // we don't care about invariant's own frame
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
if (__DEV__) {
|
||||
invariant = function(condition, format, a, b, c, d, e, f) {
|
||||
if (format === undefined) {
|
||||
throw new Error('invariant requires an error message argument');
|
||||
}
|
||||
|
||||
if (!condition) {
|
||||
var args = [a, b, c, d, e, f];
|
||||
var argIndex = 0;
|
||||
var error = new Error(
|
||||
'Invariant Violation: ' +
|
||||
format.replace(/%s/g, function() { return args[argIndex++]; })
|
||||
);
|
||||
error.framesToPop = 1; // we don't care about invariant's own frame
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = invariant;
|
||||
|
||||
Reference in New Issue
Block a user