Skip to content

Instantly share code, notes, and snippets.

@rjrodger
Created June 7, 2012 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjrodger/2890672 to your computer and use it in GitHub Desktop.
Save rjrodger/2890672 to your computer and use it in GitHub Desktop.
better node.js stacktraces from event triggered code
// the stack trace you really want that tells you how you originally got to the fs.readFile call
var stacktrace = new Error()
Error.captureStackTrace(stacktrace)
fs.readFile( path, encoding, function(err,data) {
if( err ) {
var stackerr = new Error('Unable to read file: '+path+' (error code: '+err.code+')')
stackerr.errno = err.errno
stackerr.code = err.code
stackerr.path = err.path
stackerr.stack = stacktrace.stack
return callback(stackerr)
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment