Skip to content

Commit 0c2a2e1

Browse files
authored
fix: properly nullify error stacks (#836)
`error.stack` is supposed to have error message as the first line.
1 parent e3e2da3 commit 0c2a2e1

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/chromium/crProtocolHelper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export function toConsoleMessageLocation(stackTrace: Protocol.Runtime.StackTrace
101101
export function exceptionToError(exceptionDetails: Protocol.Runtime.ExceptionDetails): Error {
102102
const message = getExceptionMessage(exceptionDetails);
103103
const err = new Error(message);
104-
err.stack = ''; // Don't report clientside error with a node stack attached
104+
// Don't report clientside error with a node stack attached
105+
err.stack = 'Error: ' + err.message; // Stack is supposed to contain error message as the first line.
105106
return err;
106107
}

src/page.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ export class Page extends platform.EventEmitter {
152152

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

src/webkit/wkPage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class WKPage implements PageDelegate {
322322
}
323323
if (level === 'error' && source === 'javascript') {
324324
const error = new Error(text);
325-
error.stack = '';
325+
error.stack = 'Error: ' + error.message; // Nullify stack. Stack is supposed to contain error message as the first line.
326326
this._page.emit(Events.Page.PageError, error);
327327
return;
328328
}

0 commit comments

Comments
 (0)