Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display detailed error trace when an error is caught in async #360

Closed
xinbenlv opened this issue Mar 26, 2017 · 2 comments
Closed

Display detailed error trace when an error is caught in async #360

xinbenlv opened this issue Mar 26, 2017 · 2 comments

Comments

@xinbenlv
Copy link
Contributor

xinbenlv commented Mar 26, 2017

By adding console.log(err); inside of process.on('unhandledRejection', (reason, promise) => {}
we will be able to print out the actual trace. I will add a PR following this issue

process.on('unhandledRejection', (reason, promise) => {
    brolog_env_1.log.error('Config', '###########################');
    brolog_env_1.log.error('Config', 'unhandledRejection: %s %s', reason, promise);
    brolog_env_1.log.error('Config', '###########################');
    promise.catch(err => {
        brolog_env_1.log.error('Config', 'unhandledRejection::catch(%s)', err.message || err);
        console.log(err);
    });
});

Example Output:

2017-03-25 20:14:00 DEBUG [main] - Got a msg type: 1
2017-03-25 20:14:00 INFO [main] - A message from Admin
ERR Config ###########################
ERR Config unhandledRejection: TypeError: Cannot read property 'name' of undefined [object Promise]
ERR Config ###########################
ERR Config unhandledRejection::catch(Cannot read property 'name' of undefined)
TypeError: Cannot read property 'name' of undefined
    at contactToStringLong (/Users/zzn/Documents/ws/haoshiyou-bot/src/listener/message.js:68:19)
    at /Users/zzn/Documents/ws/haoshiyou-bot/src/listener/message.js:164:62
    at Generator.next (<anonymous>)
    at /Users/zzn/Documents/ws/haoshiyou-bot/src/listener/message.js:7:71
    at __awaiter (/Users/zzn/Documents/ws/haoshiyou-bot/src/listener/message.js:3:12)
    at maybeBlacklistUser (/Users/zzn/Documents/ws/haoshiyou-bot/src/listener/message.js:150:12)
    at Wechaty.<anonymous> (/Users/zzn/Documents/ws/haoshiyou-bot/src/listener/message.js:47:16)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/zzn/Documents/ws/haoshiyou-bot/src/listener/message.js:4:58)
(node:59953) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 3)
    at getAsynchronousRejectionWarningObject (internal/process/promises.js:12:10)
    at rejectionHandled (internal/process/promises.js:42:21)
    at process.<anonymous> (internal/process/promises.js:21:7)
    at Promise.then (native)
    at Promise.catch (native)
    at process.on (/Users/zzn/Documents/ws/haoshiyou-bot/node_modules/wechaty/dist/src/config.js:113:18)
    at emitTwo (events.js:106:13)
    at process.emit (events.js:194:7)
    at emitPendingUnhandledRejections (internal/process/promises.js:85:22)
    at runMicrotasksCallback (internal/process/next_tick.js:67:9)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
@huan
Copy link
Member

huan commented Mar 26, 2017

Thanks for adding the detail trace log for Config.

I also have an idea of geting rid of process.on('unhandledRejection', ...) in Config, because sometimes there is no need to do this inside the FrameWork itself.

Maybe we should only enable this for DEBUG environment, like WEHATY_LOG=verbose or silly?

@xinbenlv
Copy link
Contributor Author

xinbenlv commented Mar 26, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants