Skip to content

Commit

Permalink
Protect against generating stacks failing
Browse files Browse the repository at this point in the history
Errors while generating stacks will bubble to the root. Since this technique
is a bit sketchy, we should probably protect against it.
  • Loading branch information
sebmarkbage committed Apr 11, 2020
1 parent 29bc28a commit 8a7097f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2440,13 +2440,11 @@ describe('ReactErrorBoundaries', () => {
);
});

it('should catch errors from errors in the throw phase from errors', () => {
it('should protect errors from errors in the stack generation', () => {
const container = document.createElement('div');

const evilError = {
get message() {
throw new Error('gotta catch em all');
},
message: 'gotta catch em all',
get stack() {
throw new Error('gotta catch em all');
},
Expand Down
18 changes: 11 additions & 7 deletions packages/react-reconciler/src/ReactFiberComponentStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ function describeFiber(fiber: Fiber): string {
}

export function getStackByFiberInDevAndProd(workInProgress: Fiber): string {
let info = '';
let node = workInProgress;
do {
info += describeFiber(node);
node = node.return;
} while (node);
return info;
try {
let info = '';
let node = workInProgress;
do {
info += describeFiber(node);
node = node.return;
} while (node);
return info;
} catch (x) {
return '\nError generating stack: ' + x.message + '\n' + x.stack;
}
}

0 comments on commit 8a7097f

Please sign in to comment.