Skip to content

Commit

Permalink
fix: properly nullify error stacks (#836)
Browse files Browse the repository at this point in the history
`error.stack` is supposed to have error message as the first line.
  • Loading branch information
aslushnikov committed Feb 5, 2020
1 parent e3e2da3 commit 0c2a2e1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/chromium/crProtocolHelper.ts
Expand Up @@ -101,6 +101,7 @@ export function toConsoleMessageLocation(stackTrace: Protocol.Runtime.StackTrace
export function exceptionToError(exceptionDetails: Protocol.Runtime.ExceptionDetails): Error {
const message = getExceptionMessage(exceptionDetails);
const err = new Error(message);
err.stack = ''; // Don't report clientside error with a node stack attached
// Don't report clientside error with a node stack attached
err.stack = 'Error: ' + err.message; // Stack is supposed to contain error message as the first line.
return err;
}
3 changes: 2 additions & 1 deletion src/page.ts
Expand Up @@ -152,7 +152,8 @@ export class Page extends platform.EventEmitter {

_didCrash() {
const error = new Error('Page crashed!');
error.stack = '';
// Do not report node.js stack.
error.stack = 'Error: ' + error.message; // Stack is supposed to contain error message as the first line.
this.emit('error', error);
}

Expand Down
2 changes: 1 addition & 1 deletion src/webkit/wkPage.ts
Expand Up @@ -322,7 +322,7 @@ export class WKPage implements PageDelegate {
}
if (level === 'error' && source === 'javascript') {
const error = new Error(text);
error.stack = '';
error.stack = 'Error: ' + error.message; // Nullify stack. Stack is supposed to contain error message as the first line.
this._page.emit(Events.Page.PageError, error);
return;
}
Expand Down

0 comments on commit 0c2a2e1

Please sign in to comment.