Winston exception handler doesn't handle UnhandledPromiseRejectionWarning
See original GitHub issuePlease tell us about your environment:
“devDependencies”: { “@types/chai”: “^4.1.7”, “@types/chai-as-promised”: “^7.1.0”, “@types/mocha”: “^5.2.6”, “@types/mock-fs”: “^3.6.30”, “@types/node”: “^11.11.0”, “@types/sinon”: “^7.0.9”, “@typescript-eslint/eslint-plugin”: “^1.4.2”, “@typescript-eslint/parser”: “^1.4.2”, “chai”: “^4.2.0”, “chai-as-promised”: “^7.1.1”, “eslint”: “^5.15.1”, “jest”: “^24.4.0”, “mocha”: “^6.0.2”, “mock-fs”: “^4.8.0”, “sinon”: “^7.2.7”, “ts-mockito”: “^2.3.1”, “ts-node”: “^8.0.3”, “typemoq”: “^2.1.0”, “typescript”: “^3.3.3333” }, “dependencies”: { “@types/argparse”: “^1.0.36”, “@types/fs-extra”: “^5.0.5”, “@types/request-promise”: “^4.1.42”, “argparse”: “^1.0.10”, “fs-extra”: “^7.0.1”, “moment”: “^2.24.0”, “queue”: “^6.0.0”, “request”: “^2.88.0”, “request-promise”: “^4.2.4”, “slack”: “^11.0.2”, “winston”: “^3.2.1” }
What is the problem?
Throwing Error inside the async function is not handled by Winston exception handler, an error is not being logged so information is lost.
Other information
const _format = winston.format.printf((info) => `[${moment().format('YYYY/MM/DD hh:mm:ss')}] ${info.level}: ${info.message}`);
winston.createLogger({
transports: [
new winston.transports.File({
filename: path.join(<string>EnvVars.get('ROOT_DIR'), 'logs', 'exceptions.log'), // valid path
format: winston.format.combine(this._format),
handleExceptions: true
})
]
})
(async function(){
throw new Error('test') // not working, exceptions.log is empty
})()
(function(){
throw new Error('test') // works
})()
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
I guess a workaround would be to use ->
And from there Winston would pick up an exception and log it
We added a RejectionHandler https://github.com/winstonjs/winston/blob/master/lib/winston/rejection-handler.js a few releases back – I think using that will help with your issue! Might need both exception handler and rejection handler, depending on what kinds of issues you want to catch. Feel free to follow-up if that doesn’t solve your issues.