Skip to content

Commit

Permalink
fix(helper): fix Helper.installAsyncStackHooks method (puppeteer#4478)
Browse files Browse the repository at this point in the history
Using Error.captureStackTrace instead of new Error () to avoid UnhandledPromiseRejectionWarning
  • Loading branch information
adrielcodeco authored and aslushnikov committed Jun 1, 2019
1 parent d221c02 commit ac611ba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion experimental/puppeteer-firefox/lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
3 changes: 2 additions & 1 deletion lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit ac611ba

Please sign in to comment.