fix: properly nullify error stacks (#836)

`error.stack` is supposed to have error message as the first line.
This commit is contained in:
Andrey Lushnikov 2020-02-04 19:31:57 -08:00 committed by GitHub
parent e3e2da3186
commit 0c2a2e11fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View File

@ -101,6 +101,7 @@ export function toConsoleMessageLocation(stackTrace: Protocol.Runtime.StackTrace
export function exceptionToError(exceptionDetails: Protocol.Runtime.ExceptionDetails): Error { export function exceptionToError(exceptionDetails: Protocol.Runtime.ExceptionDetails): Error {
const message = getExceptionMessage(exceptionDetails); const message = getExceptionMessage(exceptionDetails);
const err = new Error(message); 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; return err;
} }

View File

@ -152,7 +152,8 @@ export class Page extends platform.EventEmitter {
_didCrash() { _didCrash() {
const error = new Error('Page crashed!'); 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); this.emit('error', error);
} }

View File

@ -322,7 +322,7 @@ export class WKPage implements PageDelegate {
} }
if (level === 'error' && source === 'javascript') { if (level === 'error' && source === 'javascript') {
const error = new Error(text); 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); this._page.emit(Events.Page.PageError, error);
return; return;
} }