Skip to content

Commit

Permalink
changed URL format and removed stack info
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyan Zhang committed Jun 3, 2016
1 parent 889416b commit 86e2624
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/renderers/dom/__tests__/ReactDOMProduction-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ describe('ReactDOMProduction', function() {
var container = document.createElement('div');
ReactDOM.render(<Component />, container);
}).toThrowError(
/React: production error #109\. Visit http:\/\/facebook\.github\.io\/react\/docs\/error-codes\.html\?invariant=109&args=%22Component%22&stack=%22Error.*reactProdInvariant.*%22 for more details\./ // eslint-disable-line max-len
'React: production error #109. Visit ' +
'http://facebook.github.io/react/docs/error-codes.html?invariant=109&args[]=Component' +
' for more details.'
);
});
});
15 changes: 10 additions & 5 deletions src/shared/utils/__tests__/reactProdInvariant-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*
* @emails react-core
*/
/* eslint-disable max-len */
'use strict';

var reactProdInvariant;
Expand All @@ -23,19 +22,25 @@ describe('reactProdInvariant', function() {
expect(function() {
reactProdInvariant(124, 'foo', 'bar');
}).toThrowError(
/React: production error #124\. Visit http:\/\/facebook\.github\.io\/react\/docs\/error-codes\.html\?invariant=124&args=%22foo%22&args=%22bar%22&stack=%22Error.*reactProdInvariant.*%22 for more details\./
'React: production error #124. Visit ' +
'http://facebook.github.io/react/docs/error-codes.html?invariant=124&args[]=foo&args[]=bar' +
' for more details.'
);

expect(function() {
reactProdInvariant(20);
}).toThrowError(
/React: production error #20\. Visit http:\/\/facebook\.github\.io\/react\/docs\/error-codes\.html\?invariant=20&stack=%22Error.*reactProdInvariant.*%22 for more details\./
'React: production error #20. Visit ' +
'http://facebook.github.io/react/docs/error-codes.html?invariant=20' +
' for more details.'
);

expect(function() {
reactProdInvariant(77, 'foo', 'bar', 'and', 'what', 'else');
reactProdInvariant(77, '<div>', '&?bar');
}).toThrowError(
/React: production error #77\. Visit http:\/\/facebook\.github\.io\/react\/docs\/error-codes\.html\?invariant=77&args=%22foo%22&args=%22bar%22&args=%22and%22&args=%22what%22&args=%22else%22&stack=%22Error.*reactProdInvariant.*%22 for more details\./
'React: production error #77. Visit ' +
'http://facebook.github.io/react/docs/error-codes.html?invariant=77&args[]=%3Cdiv%3E&args[]=%26%3Fbar' +
' for more details.'
);
});
});
20 changes: 6 additions & 14 deletions src/shared/utils/reactProdInvariant.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,23 @@
*/
function reactProdInvariant(code, a, b, c, d, e, f) {
var argCount = arguments.length - 1;
var error = new Error('');

var format = (
var message = (
'React: production error #' + code + '. ' +
'Visit http://facebook.github.io/react/docs/' +
'error-codes.html?invariant=' + code
);

while (argCount > 0) {
format += '&args=%22%s%22';
argCount--;
for (var argIdx = 0; argIdx < argCount; argIdx++) {
message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
}

format += '&stack=%22' + (error.stack ? encodeURIComponent(error.stack) : '') + '%22';
format += ' for more details.';

var args = [a, b, c, d, e, f];
var argIndex = 0;
error.message = format.replace(/%s/g, function() {
return args[argIndex++];
});
message += ' for more details.';

var error = new Error(message);
error.name = 'Invariant Violation';

error.framesToPop = 1; // we don't care about reactProdInvariant's own frame

throw error;
}

Expand Down

0 comments on commit 86e2624

Please sign in to comment.