question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not log variables that are `null` or `undefined`

See original GitHub issue

Hello! I’m having an issue with logging variables if I expect them to sometimes be null or undefined.

I am using a custom formatter, but disabling this does not fix the problem.

Error when console.log()-ing the error:

TypeError: Cannot read property 'message' of undefined
    at DerivedLogger.(anonymous function) [as debug] (<...>\node_modules\winston\lib\winston\create-logger.js:43:26)

And from my logger logging its own error,:

15:52:25 error: Cannot read property 'message' of undefined

Steps to reproduce

  1. Call a winston logger with an undefined variable or object, e.g. logger.debug(null); or let myVar = undefined; logger.info(myVar);.

Expected behaviour

  1. Winston logs the error according to all the formats applied to it.
  2. Execution continues.

Actual behaviour

  1. Winston logs a Cannot read property 'message' of null/undefined error.
  2. Execution halts.

System info

  • Windows 10
  • NodeJS v. 8.9.1
  • npm v. 5.6.0
  • winston v. 3.0.0-rc1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DABHcommented, Apr 24, 2018

Sorry, does this also happen with the latest rc (3.0.0-rc5)? If so, any chance you can show us how your logger and transports are setup/defined?

0reactions
dagerikhlcommented, Apr 25, 2018

Wow, I’m really nailing it with the searches! Thanks for clearing that up, and thanks for the help. If I think of some way to handle it, I’ll be sure to comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript: Check if Variable is undefined or null - Stack Abuse
In this short guide, you'll learn how to check if a variable is undefined, null or nil in vanilla JavaScript and with Lodash...
Read more >
How can I determine if a variable is 'undefined' or 'null'?
This should work for any variable that is either undeclared or declared and explicitly set to null or undefined. The boolean expression should...
Read more >
How to Determine If Variable is Undefined or NULL in JavaScript
Answer: Use the equality operator ( == ). In JavaScript if a variable has been declared, but has not been assigned a value,...
Read more >
Check if Variable is NULL or Undefined in JavaScript
Use the logical OR (||) operator to check if a variable is null or undefined . The if block will only run if...
Read more >
How to Check if the Variable is undefined or null in Javascript
In JavaScript, undefined and null are both falsy values, which indicate no value or absence of values within a variable. Users can check...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found