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.
Andrew Zich committed
Jul 3, 2014 at 13:53 UTC
559eb899657b7717e2a1013cd860407cb89c2b3c
1 file changed
+17
-19
src/vendor/core/invariant.js
+17
-19
@@ -29,34 +29,32 @@
29
* will remain to ensure logic does not differ in production.
30
*/
31
32
-var invariant = function(condition) {
33
- if (!condition) {
34
- var error = new Error(
35
- 'Minified exception occured; use the non-minified dev environment for ' +
36
- 'the full error message and additional helpful warnings.'
37
- );
38
- error.framesToPop = 1;
39
- throw error;
40
- }
41
-};
42
-
43
-if (__DEV__) {
44
- invariant = function(condition, format, a, b, c, d, e, f) {
32
+var invariant = function(condition, format, a, b, c, d, e, f) {
33
+ if (__DEV__) {
34
if (format === undefined) {
35
throw new Error('invariant requires an error message argument');
36
}
37
+ }
38
49
- if (!condition) {
39
+ if (!condition) {
40
+ var error;
41
+ if (format === undefined) {
42
+ error = new Error(
43
+ 'Minified exception occurred; use the non-minified dev environment ' +
44
+ 'for the full error message and additional helpful warnings.'
45
+ );
46
+ } else {
47
var args = [a, b, c, d, e, f];
48
var argIndex = 0;
52
- var error = new Error(
49
+ error = new Error(
50
'Invariant Violation: ' +
51
format.replace(/%s/g, function() { return args[argIndex++]; })
52
);
56
- error.framesToPop = 1; // we don't care about invariant's own frame
57
- throw error;
53
}
59
- };
60
-}
54
+
55
+ error.framesToPop = 1; // we don't care about invariant's own frame
56
+ throw error;
57
+ }
58
+};
59
60
module.exports = invariant;