Comparing version 1.3.1 to 1.3.2
@@ -13,3 +13,3 @@ var extsprintf = require('extsprintf'); | ||
/* ... */ | ||
callback(); | ||
return (callback()); | ||
}); | ||
@@ -20,10 +20,9 @@ } | ||
checkFile('/nonexistent', function (err) { | ||
if (err) { | ||
if (err) | ||
/* Wrap the "checkFile" error. */ | ||
return (callback(new verror.WError( | ||
err, 'request failed'))); | ||
} | ||
/* ... */ | ||
callback(); | ||
return (callback()); | ||
}); | ||
@@ -30,0 +29,0 @@ } |
@@ -58,5 +58,5 @@ /* | ||
} | ||
mod_util.inherits(VError, Error); | ||
VError.prototype.constructor = VError; | ||
VError.prototype.name = VError; | ||
VError.prototype.name = 'VError'; | ||
@@ -132,2 +132,3 @@ VError.prototype.toString = function ve_toString() | ||
} | ||
mod_util.inherits(WError, Error); | ||
@@ -134,0 +135,0 @@ |
{ | ||
"name": "verror", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "richer JavaScript errors", | ||
@@ -16,3 +16,7 @@ "main": "./lib/verror.js", | ||
"engines": [ "node >=0.6.0" ] | ||
"engines": [ "node >=0.6.0" ], | ||
"scripts": { | ||
"test": "make test" | ||
} | ||
} |
# verror: richer JavaScript errors | ||
This module provides two classes: VError, for accretive errors, and WError, for | ||
wrapping errors. These are best demonstrated by example. | ||
wrapping errors. Both support printf-style error messages using extsprintf. | ||
## Printf-style errors | ||
## VError for accretive error messages | ||
At the most basic level, VError is just like JavaScript's Error class, but with | ||
@@ -23,3 +22,3 @@ printf-style arguments: | ||
"read" operation failed | ||
at Object.<anonymous> (/Users/dap/work/node-verror/examples/varargs.js:4:11) | ||
at Object.<anonymous> (/Users/dap/node-verror/examples/varargs.js:4:11) | ||
at Module._compile (module.js:449:26) | ||
@@ -32,2 +31,5 @@ at Object.Module._extensions..js (module.js:467:10) | ||
## VError for accretive error messages | ||
More interestingly, you can use VError to build up an error describing what | ||
@@ -72,3 +74,3 @@ happened at various levels in the stack. For example, suppose you have a | ||
The idea is that the lowest level (Node's "fs.stat" function) generates an | ||
The idea here is that the lowest level (Node's "fs.stat" function) generates an | ||
arbitrary error, and each higher level (request handler and stat callback) | ||
@@ -90,2 +92,3 @@ creates a new VError that annotates the previous error with what it was doing, | ||
## WError for wrapped errors | ||
@@ -98,6 +101,6 @@ | ||
them in the audit log entry for the request. In that case, you can use a | ||
WError, which is created exactly like VError (and supports both printf-style | ||
arguments and an optional cause), but the resulting "message" only contains the | ||
top-level error. Using the same example above, but replacing the VError in | ||
handleRequest with WError, we get this output: | ||
WError, which is created exactly like VError (and also supports both | ||
printf-style arguments and an optional cause), but the resulting "message" only | ||
contains the top-level error. Using the same example above, but replacing the | ||
VError in handleRequest with WError, we get this output: | ||
@@ -111,1 +114,23 @@ request failed | ||
stat '/nonexistent' | ||
and as usual, the "stack" member shows the stack trace: | ||
WError: failed to handle request; caused by WError: failed to stat "/nonexistent"; caused by Error: ENOENT, stat '/nonexistent' | ||
at /Users/dap/work/node-verror/examples/werror.js:10:13 | ||
at Object.oncomplete (fs.js:297:15) | ||
Caused by: WError: failed to stat "/nonexistent"; caused by Error: ENOENT, stat '/nonexistent' | ||
at /Users/dap/work/node-verror/examples/werror.js:7:20 | ||
at Object.oncomplete (fs.js:297:15) | ||
Caused by: Error: ENOENT, stat '/nonexistent' | ||
# Contributing | ||
Contributions welcome. Code should be "make check" clean. To run "make check", | ||
you'll need these tools: | ||
* https://github.com/davepacheco/jsstyle | ||
* https://github.com/davepacheco/javascriptlint | ||
If you're changing something non-trivial or user-facing, you may want to submit | ||
an issue first. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40971
17
533
131
4
1