The VError
module combines errors and adds additional context from the current level while keeping the existing information intact. This is useful because the additional information helps us determine exactly the different levels the error has been propagated through.
To picture this better, let's create a brief example:
require('clarify'); var VError = require('verror'); var err1 = new Error('No such file or directory'); var err2 = new VError(err1, 'failed to stat "%s"', '/junk'); var err3 = new VError(err2, 'request failed'); var err = err3; while (err) { console.log(err.stack); console.log('--------'); if (err.cause) { err = err.cause(); } else { err = null; } }
Since we use the
clarify
module to strip the Node core method calls from the stack trace, we will get the following data logged to the terminal:
$ node verror-test.js VError: request failed: failed to stat "/junk": No such file or directory at Object.<anonymous> (/Users/alexandruvladutu...