From ac611bacac546a8a9d1a70bc1727590b89173903 Mon Sep 17 00:00:00 2001 From: Adriel Codeco Date: Fri, 31 May 2019 23:39:32 -0300 Subject: [PATCH] fix(helper): fix Helper.installAsyncStackHooks method (#4478) Using Error.captureStackTrace instead of new Error () to avoid UnhandledPromiseRejectionWarning --- experimental/puppeteer-firefox/lib/helper.js | 3 ++- lib/helper.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/experimental/puppeteer-firefox/lib/helper.js b/experimental/puppeteer-firefox/lib/helper.js index 81dd61d6..78dd01d6 100644 --- a/experimental/puppeteer-firefox/lib/helper.js +++ b/experimental/puppeteer-firefox/lib/helper.js @@ -28,7 +28,8 @@ class Helper { if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function' || method.constructor.name !== 'AsyncFunction') continue; Reflect.set(classType.prototype, methodName, function(...args) { - const syncStack = new Error(); + const syncStack = {}; + Error.captureStackTrace(syncStack); return method.call(this, ...args).catch(e => { const stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1); const clientStack = stack.substring(stack.indexOf('\n')); diff --git a/lib/helper.js b/lib/helper.js index 8fc0d16f..3c158133 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -107,7 +107,8 @@ class Helper { if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function' || method.constructor.name !== 'AsyncFunction') continue; Reflect.set(classType.prototype, methodName, function(...args) { - const syncStack = new Error(); + const syncStack = {}; + Error.captureStackTrace(syncStack); return method.call(this, ...args).catch(e => { const stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1); const clientStack = stack.substring(stack.indexOf('\n'));