fix(helper): fix Helper.installAsyncStackHooks method (#4478)
Using Error.captureStackTrace instead of new Error () to avoid UnhandledPromiseRejectionWarning
This commit is contained in:
parent
d221c02c13
commit
ac611bacac
@ -28,7 +28,8 @@ class Helper {
|
|||||||
if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function' || method.constructor.name !== 'AsyncFunction')
|
if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function' || method.constructor.name !== 'AsyncFunction')
|
||||||
continue;
|
continue;
|
||||||
Reflect.set(classType.prototype, methodName, function(...args) {
|
Reflect.set(classType.prototype, methodName, function(...args) {
|
||||||
const syncStack = new Error();
|
const syncStack = {};
|
||||||
|
Error.captureStackTrace(syncStack);
|
||||||
return method.call(this, ...args).catch(e => {
|
return method.call(this, ...args).catch(e => {
|
||||||
const stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1);
|
const stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1);
|
||||||
const clientStack = stack.substring(stack.indexOf('\n'));
|
const clientStack = stack.substring(stack.indexOf('\n'));
|
||||||
|
@ -107,7 +107,8 @@ class Helper {
|
|||||||
if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function' || method.constructor.name !== 'AsyncFunction')
|
if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function' || method.constructor.name !== 'AsyncFunction')
|
||||||
continue;
|
continue;
|
||||||
Reflect.set(classType.prototype, methodName, function(...args) {
|
Reflect.set(classType.prototype, methodName, function(...args) {
|
||||||
const syncStack = new Error();
|
const syncStack = {};
|
||||||
|
Error.captureStackTrace(syncStack);
|
||||||
return method.call(this, ...args).catch(e => {
|
return method.call(this, ...args).catch(e => {
|
||||||
const stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1);
|
const stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1);
|
||||||
const clientStack = stack.substring(stack.indexOf('\n'));
|
const clientStack = stack.substring(stack.indexOf('\n'));
|
||||||
|
Loading…
Reference in New Issue
Block a user