Skip to content

Commit

Permalink
Handle undefined errors in getAllInfo (#2208)
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindrs authored Oct 18, 2022
1 parent a52608c commit 8769d47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/winston/exception-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ module.exports = class ExceptionHandler {
* @returns {mixed} - TODO: add return description.
*/
getAllInfo(err) {
let { message } = err;
if (!message && typeof err === 'string') {
message = err;
let message = null;
if (err) {
message = typeof err === 'string' ? err : err.message;
}

return {
Expand All @@ -84,9 +84,9 @@ module.exports = class ExceptionHandler {
level: 'error',
message: [
`uncaughtException: ${(message || '(no error message)')}`,
err.stack || ' No stack trace'
err && err.stack || ' No stack trace'
].join('\n'),
stack: err.stack,
stack: err && err.stack,
exception: true,
date: new Date().toString(),
process: this.getProcessInfo(),
Expand Down
6 changes: 6 additions & 0 deletions test/unit/winston/exception-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ describe('ExceptionHandler', function () {
helpers.throw('wtf this error');
});

it('.getAllInfo(undefined)', function () {
var handler = helpers.exceptionHandler();
// eslint-disable-next-line no-undefined
handler.getAllInfo(undefined);
});

after(function () {
//
// Restore normal `runTest` functionality
Expand Down

0 comments on commit 8769d47

Please sign in to comment.