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.

Enable a better unhandled exception experience

See original GitHub issue

tldr: Preserve formatting for handled exceptions in a transport when json=false.

Currently, at Clipboard.com we wrap all node applications in an upstart script that essentially ends up as:

/usr/local/bin/node $APP 1>>$LOGFILE 2>>$ERRORFILE

Combined with console.log and console.error, we’re in a position to monitor for unhanded exceptions which are still human readable in the error log.

I’ve been evaluating winston, but I have one gripe re: error handling with unhanded exceptions.

Here’s the output of a unhanded exception to the console:

node.js:201
    throw e; // process.nextTick error, or 'error' event on first tick
          ^
ReferenceError: x is not defined
    at Object.<anonymous> (/clipboard/src/node/winston-log.js:56:1)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:470:10)
    at EventEmitter._tickCallback (node.js:192:40)

When we catch this with stderr, it’s nice and human readable. However, when we use Winston combined with a File transport and handled exceptions (with json=false) you get the following:

13 Jan 13:37:46 - error: uncaughtException pid=4874, uid=0, gid=0, cwd=/var/log/clipboard, execPath=/usr/local/bin/node, version=v0.6.5, argv=[node, /clipboard/src/node/winston-log.js], rss=12767232, heapTotal=7829952, heapUsed=3200976, loadavg=[0.6064453125, 0.48388671875, 0.4375], uptime=10935.226142303, trace=[column=1, file=/clipboard/src/node/winston-log.js, function=, line=56, method=null, native=false, column=26, file=module.js, function=Module._compile, line=432, method=_compile, native=false, column=10, file=module.js, function=Object..js, line=450, method=.js, native=false, column=31, file=module.js, function=Module.load, line=351, method=load, native=false, column=12, file=module.js, function=Function._load, line=310, method=_load, native=false, column=10, file=module.js, function=Array.0, line=470, method=0, native=false, column=40, file=node.js, function=EventEmitter._tickCallback, line=192, method=_tickCallback, native=false], stack=[ReferenceError: x is not defined,     at Object.<anonymous> (/clipboard/src/node/winston-log.js:56:1),     at Module._compile (module.js:432:26),     at Object..js (module.js:450:10),     at Module.load (module.js:351:31),     at Function._load (module.js:310:12),     at Array.0 (module.js:470:10),     at EventEmitter._tickCallback (node.js:192:40)]

Of course, this wraps on most consoles, and you end up with something to this effect:

13 Jan 13:37:46 - error: uncaughtException pid=4874, uid=0, gid=0, cwd=/var/log/clipboard, execPath=/usr/local/bin/node,
version=v0.6.5, argv=[node, /clipboard/src/node/winston-log.js], rss=12767232, heapTotal=7829952, heapUsed=3200976,
loadavg=[0.6064453125, 0.48388671875, 0.4375], uptime=10935.226142303, trace=[column=1,
file=/clipboard/src/node/winston-log.js, function=, line=56, method=null, native=false, column=26, file=module.js, 
function=Module._compile, line=432, method=_compile, native=false, column=10, file=module.js, function=Object..js,
line=450, method=.js, native=false, column=31, file=module.js, function=Module.load, line=351, method=load, native=false,
column=12, file=module.js, function=Function._load, line=310, method=_load, native=false, column=10, file=module.js,
function=Array.0, line=470, method=0, native=false, column=40, file=node.js, function=EventEmitter._tickCallback, line=192,
method=_tickCallback, native=false], stack=[ReferenceError: x is not defined,     at Object.<anonymous>
(/clipboard/src/node/winston-log.js:56:1),     at Module._compile (module.js:432:26),     at Object..js (module.js:450:10),     at
Module.load (module.js:351:31),     at Function._load (module.js:310:12),     at Array.0 (module.js:470:10),     at
EventEmitter._tickCallback (node.js:192:40)]

When we look at this output, it’s exceptionally difficult to digest what’s going on.

Link from IRC with some commentary: https://gist.github.com/1608837

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:24 (7 by maintainers)

github_iconTop GitHub Comments

14reactions
samejackcommented, Feb 27, 2015

use humanReadableUnhandledException:true config to fix it. as follows

{
      level: 'debug',
      humanReadableUnhandledException: true,
      handleExceptions: true,
      json: false,
      colorize: true
    }
0reactions
indexzerocommented, Feb 27, 2015

Oh yeah, this is totally fixed. Thanks for the comment @samejack!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Internet Explorer Unhandled Exceptions
1. Launch Internet Explorer. · 2. Click the "Tools" (gear) icon, and then select "Manage Add-ons." Click "All Add-ons" under the Show header....
Read more >
Visual Studio 2015 break on unhandled exceptions not working
So just right-click an exception or an entire group and disable the "Continue when unhandled in user code" flag. Unfortunately, the "Additional Actions" ......
Read more >
Understanding Exceptions while debugging with Visual Studio
In Visual Studio, when exceptions are thrown or end up unhandled, the debugger can help you debug these by breaking just like it...
Read more >
"Exception in acexperience.arx ARX Command" when starting ...
Unhandled Exception c00000fd (c00000fdh) at address f93f0584h" ... (see How to enable or disable the Desktop Analytics Program in AutoCAD).
Read more >
Window: unhandledrejection event - Web APIs | MDN
Allowing the unhandledrejection event to bubble will eventually result in an error message being output to the console.
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