verror
Advanced tools
Comparing version 1.8.1 to 1.9.0
@@ -7,2 +7,6 @@ # Changelog | ||
## v1.9.0 | ||
* #47 could use VError.hasCauseWithName() | ||
## v1.8.1 | ||
@@ -9,0 +13,0 @@ |
@@ -278,3 +278,3 @@ /* | ||
mod_assertplus.ok(mod_isError(err), 'err must be an Error'); | ||
mod_assertplus.string(name); | ||
mod_assertplus.string(name, 'name'); | ||
mod_assertplus.ok(name.length > 0, 'name cannot be empty'); | ||
@@ -292,2 +292,7 @@ | ||
VError.hasCauseWithName = function (err, name) | ||
{ | ||
return (VError.findCauseByName(err, name) !== null); | ||
}; | ||
VError.fullStack = function (err) | ||
@@ -294,0 +299,0 @@ { |
{ | ||
"name": "verror", | ||
"version": "1.8.1", | ||
"version": "1.9.0", | ||
"description": "richer JavaScript errors", | ||
@@ -5,0 +5,0 @@ "main": "./lib/verror.js", |
@@ -195,3 +195,3 @@ # verror: rich JavaScript errors | ||
rather than checking the `name` field directly. | ||
* If the caller logs this error, the logs can be analyzed to aggregate | ||
* If the caller logs this error, the logs can be analyzed to aggregate | ||
errors by cause, by RPC method name, by user, or whatever. Or the | ||
@@ -323,3 +323,22 @@ error can be correlated with other events for the same rpcMsgid. | ||
### `VError.findCauseByName(err, name)` | ||
The `findCauseByName()` function traverses the cause chain for `err`, looking | ||
for an error whose `name` property matches the passed in `name` value. If no | ||
match is found, `null` is returned. | ||
If all you want is to know _whether_ there's a cause (and you don't care what it | ||
is), you can use `VError.hasCauseWithName(err, name)`. | ||
If a vanilla error or a non-VError error is passed in, then there is no cause | ||
chain to traverse. In this scenario, the function will check the `name` | ||
property of only `err`. | ||
### `VError.hasCauseWithName(err, name)` | ||
Returns true if and only if `VError.findCauseByName(err, name)` would return | ||
a non-null value. This essentially determines whether `err` has any cause in | ||
its cause chain that has name `name`. | ||
## Examples | ||
@@ -397,3 +416,3 @@ | ||
at node.js:935:3 | ||
You can also print the complete stack trace of combined `Error`s by using | ||
@@ -400,0 +419,0 @@ `VError.fullStack(err).` |
33897
497
7
356