From 0c2a2e11fd1e1ab97ab286e0b9a9f134da23cb15 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 4 Feb 2020 19:31:57 -0800 Subject: [PATCH] fix: properly nullify error stacks (#836) `error.stack` is supposed to have error message as the first line. --- src/chromium/crProtocolHelper.ts | 3 ++- src/page.ts | 3 ++- src/webkit/wkPage.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/chromium/crProtocolHelper.ts b/src/chromium/crProtocolHelper.ts index 24cd0717ba..4fbef2d7e7 100644 --- a/src/chromium/crProtocolHelper.ts +++ b/src/chromium/crProtocolHelper.ts @@ -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; } diff --git a/src/page.ts b/src/page.ts index 75092a2923..32de48a3bc 100644 --- a/src/page.ts +++ b/src/page.ts @@ -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); } diff --git a/src/webkit/wkPage.ts b/src/webkit/wkPage.ts index 13629bb8b5..4c88459e10 100644 --- a/src/webkit/wkPage.ts +++ b/src/webkit/wkPage.ts @@ -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; }