{
  "_from": "verror@1.3.6",
  "_id": "verror@1.3.6",
  "_location": "/fsevents/verror",
  "_npmUser": {
    "email": "dap@cs.brown.edu",
    "name": "dap"
  },
  "_npmVersion": "1.1.65",
  "_phantomChildren": {},
  "_requiredBy": [
    "/fsevents/jsprim"
  ],
  "_resolved": "https://registry.npmjs.org/verror/-/verror-1.3.6.tgz",
  "_shasum": "cff5df12946d297d2baaefaa2689e25be01c005c",
  "_shrinkwrap": null,
  "bugs": {
    "url": "https://github.com/davepacheco/node-verror/issues"
  },
  "dependencies": {
    "extsprintf": "1.0.2"
  },
  "description": "richer JavaScript errors",
  "devDependencies": {},
  "directories": {},
  "dist": {
    "shasum": "cff5df12946d297d2baaefaa2689e25be01c005c",
    "tarball": "http://registry.npmjs.org/verror/-/verror-1.3.6.tgz"
  },
  "engines": [
    "node >=0.6.0"
  ],
  "homepage": "https://github.com/davepacheco/node-verror#readme",
  "main": "./lib/verror.js",
  "maintainers": [
    {
      "email": "dap@cs.brown.edu",
      "name": "dap"
    }
  ],
  "name": "verror",
  "optionalDependencies": {},
  "readme": "# verror: richer JavaScript errors\n\nThis module provides two classes: VError, for accretive errors, and WError, for\nwrapping errors.  Both support printf-style error messages using extsprintf.\n\n## Printf-style errors\n\nAt the most basic level, VError is just like JavaScript's Error class, but with\nprintf-style arguments:\n\n    var verror = require('verror');\n\n    var opname = 'read';\n    var err = new verror.VError('\"%s\" operation failed', opname);\n    console.log(err.message);\n    console.log(err.stack);\n\nThis prints:\n\n    \"read\" operation failed\n    \"read\" operation failed\n        at Object.<anonymous> (/Users/dap/node-verror/examples/varargs.js:4:11)\n        at Module._compile (module.js:449:26)\n        at Object.Module._extensions..js (module.js:467:10)\n        at Module.load (module.js:356:32)\n        at Function.Module._load (module.js:312:12)\n        at Module.runMain (module.js:492:10)\n        at process.startup.processNextTick.process._tickCallback (node.js:244:9)\n\n\n## VError for accretive error messages\n\nMore interestingly, you can use VError to build up an error describing what\nhappened at various levels in the stack.  For example, suppose you have a\nrequest handler that stats a file and fails if it doesn't exist:\n\n    var fs = require('fs');\n    var verror = require('verror');\n\n    function checkFile(filename, callback) {\n        fs.stat(filename, function (err) {\n            if (err)\n\t\t/* Annotate the \"stat\" error with what we were doing. */\n\t    \treturn (callback(new verror.VError(err,\n\t\t    'failed to check \"%s\"', filename)));\n\n\t    /* ... */\n        });\n    }\n\n    function handleRequest(filename, callback) {\n    \tcheckFile('/nonexistent', function (err) {\n    \t    if (err) {\n    \t    \t/* Annotate the \"checkFile\" error with what we were doing. */\n    \t    \treturn (callback(new verror.VError(err, 'request failed')));\n    \t    }\n\n    \t    /* ... */\n    \t});\n    }\n\n    handleRequest('/nonexistent', function (err) {\n\tif (err)\n\t\tconsole.log(err.message);\n\t/* ... */\n    });\n\nSince the file \"/nonexistent\" doesn't exist, this prints out:\n\n    request failed: failed to check \"/nonexistent\": ENOENT, stat '/nonexistent'\n\nThe idea here is that the lowest level (Node's \"fs.stat\" function) generates an\narbitrary error, and each higher level (request handler and stat callback)\ncreates a new VError that annotates the previous error with what it was doing,\nso that the result is a clear message explaining what failed at each level.\n\nThis plays nicely with extsprintf's \"%r\" specifier, which prints out a\nJava-style stacktrace with the whole chain of exceptions:\n\n    EXCEPTION: VError: request failed: failed to check \"/nonexistent\": ENOENT, stat '/nonexistent'\n        at /Users/dap/work/node-verror/examples/levels.js:21:21\n        at /Users/dap/work/node-verror/examples/levels.js:9:12\n        at Object.oncomplete (fs.js:297:15)\n    Caused by: EXCEPTION: VError: failed to check \"/nonexistent\": ENOENT, stat '/nonexistent'\n        at /Users/dap/work/node-verror/examples/levels.js:9:21\n        at Object.oncomplete (fs.js:297:15)\n    Caused by: EXCEPTION: Error: Error: ENOENT, stat '/nonexistent'\n\n\n## WError for wrapped errors\n\nSometimes you don't want an Error's \"message\" field to include the details of\nall of the low-level errors, but you still want to be able to get at them\nprogrammatically.  For example, in an HTTP server, you probably don't want to\nspew all of the low-level errors back to the client, but you do want to include\nthem in the audit log entry for the request.  In that case, you can use a\nWError, which is created exactly like VError (and also supports both\nprintf-style arguments and an optional cause), but the resulting \"message\" only\ncontains the top-level error.  It's also more verbose, including the class\nassociated with each error in the cause chain.  Using the same example above,\nbut replacing the VError in handleRequest with WError, we get this output:\n\n    request failed\n\nThat's what we wanted -- just a high-level summary for the client.  But we can\nget the object's toString() for the full details:\n\n    WError: request failed; caused by WError: failed to check \"/nonexistent\";\n    caused by Error: ENOENT, stat '/nonexistent'\n\n# Contributing\n\nContributions welcome.  Code should be \"make check\" clean.  To run \"make check\",\nyou'll need these tools:\n\n* https://github.com/davepacheco/jsstyle\n* https://github.com/davepacheco/javascriptlint\n\nIf you're changing something non-trivial or user-facing, you may want to submit\nan issue first.\n",
  "readmeFilename": "README.md",
  "repository": {
    "type": "git",
    "url": "git://github.com/davepacheco/node-verror.git"
  },
  "scripts": {
    "test": "make test"
  },
  "version": "1.3.6"
}
