About Constructor:
All of these forms construct a new VError that behaves just like the built-in
JavaScript Error class, with some additional methods described below.
About Properties:
For all of these classes except PError, the printf-style arguments passed to
the constructor are processed with sprintf() to form a message.
For WError, this becomes the complete message property. For SError and
VError, this message is prepended to the message of the cause, if any
(with a suitable separator), and the result becomes the message property.
The stack property is managed entirely by the underlying JavaScript
implementation. It's generally implemented using a getter function because
constructing the human-readable stack trace is somewhat expensive.
arg...(String | VErrorOptions | Error)? sprintf args, options or causeargs...String? sprintf args
nameString Programmatically-usable name of the error.messageString Human-readable summary of the failure. Programmatically-accessible details are provided throughVError.info(err)class method.stackString Human-readable stack trace where the Error was constructed.
// This is the most general form. You can specify any supported options
// including "cause" and "info") this way.</caption>
new VError(options, sprintf_args...)// This is a useful shorthand when the only option you need is "cause".
new VError(cause, sprintf_args...)// This is a useful shorthand when you don't need any options at all.
new VError(sprintf_args...)Appends any keys/fields to the existing jse_info. this can stomp over any existing fields.
objObject source obj to assign fields from
Returns Object new info object
Instance level convenience method vs using the static methods on VError.
Returns Object info object
A string representing the VError.
Returns String string representation
This method is provided for compatibility. New callers should use
VError.cause() instead. That method also uses the saner null return value
when there is no cause.
Returns (undefined | Error) Error cause if any
Checks if an error is a VError or VError sub-class.
errError error
Returns Boolean is a VError or VError sub-class
Appends any keys/fields to the jse_info. This can stomp over any existing
fields.
Note: This method is static because in this way we don't need to check on
VError versions to be sure assignInfo method is supported.
Returns Object new info object
Returns the next Error in the cause chain for err, or null if there is no
next error. See the cause argument to the constructor.
Errors can have arbitrarily long cause chains. You can walk the cause
chain by invoking VError.cause(err) on each subsequent return value.
If err is not a VError, the cause is null.
errVError error
Returns (undefined | Error) Error cause if any
Returns an object with all of the extra error information that's been
associated with this Error and all of its causes. These are the properties
passed in using the info option to the constructor. Properties not
specified in the constructor for this Error are implicitly inherited from
this error's cause.
These properties are intended to provide programmatically-accessible metadata about the error. For an error that indicates a failure to resolve a DNS name, informational properties might include the DNS name to be resolved, or even the list of resolvers used to resolve it. The values of these properties should generally be plain objects (i.e., consisting only of null, undefined, numbers, booleans, strings, and objects and arrays containing only other plain objects).
errVError error
Returns Object info object
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.
Returns (null | Error) cause if any
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.
Returns Boolean has cause
Returns a string containing the full stack trace, with all nested errors
recursively reported as 'caused by:' + err.stack.
errVError error
Returns String full stack trace
Given an array of Error objects (possibly empty), return a single error representing the whole collection of errors. If the list has:
- 0 elements, returns
null - 1 element, returns the sole error
- more than 1 element, returns a MultiError referencing the whole list
This is useful for cases where an operation may produce any number of errors,
and you ultimately want to implement the usual callback(err) pattern.
You can accumulate the errors in an array and then invoke
callback(VError.errorFromList(errors)) when the operation is complete.
Returns (null | Error | MultiError) single or multi error if any
Convenience function for iterating an error that may itself be a MultiError.
In all cases, err must be an Error. If err is a MultiError, then func
is invoked as func(errorN) for each of the underlying errors of the
MultiError.
If err is any other kind of error, func is invoked once as func(err).
In all cases, func is invoked synchronously.
This is useful for cases where an operation may produce any number of warnings that may be encapsulated with a MultiError -- but may not be.
This function does not iterate an error's cause chain.
Returns undefined no return value
Type: Object
nameString Name of the error.causeError? Indicates that the new error was caused bycause.strictBoolean If true, thennullandundefinedvalues insprintf_argsare passed through tosprintf()(optional, defaultfalse)constructorOptFunction? -If specified, then the stack trace for this error ends at functionconstructorOpt.infoObject? Specifies arbitrary informational properties.skipPrintfBoolean If true, thensprintf()is not called (optional, defaultfalse)
Extends VError
PError is like VError, but the message is not run through printf-style templating.
arg...(String | VErrorOptions | Error)? sprintf args, options or causeargs...String? sprintf args
Extends VError
SError is like VError, but stricter about types. You cannot pass "null" or "undefined" as string arguments to the formatter.
arg...(String | VErrorOptions | Error)? sprintf args, options or causeargs...String? sprintf args
Extends VError
Represents a collection of errors for the purpose of consumers that generally only deal with one error. Callers can extract the individual errors contained in this object, but may also just treat it as a normal single error, in which case a summary message will be printed.
// `error_list` is an array of at least one `Error` object.
new MultiError(error_list)
// The cause of the MultiError is the first error provided. None of the
// other `VError` options are supported. The `message` for a MultiError
// consists the `message` from the first error, prepended with a message
// indicating that there were other errors.
//For example:
err = new MultiError([
new Error('failed to resolve DNS name "abc.example.com"'),
new Error('failed to resolve DNS name "def.example.com"'),
]);
console.error(err.message);
// outputs:
// first of 2 errors: failed to resolve DNS name "abc.example.com"Returns an array of the errors used to construct this MultiError.
Extends VError
WError for wrapping errors while hiding the lower-level messages from the top-level error. This is useful for API endpoints where you don't want to expose internal error messages, but you still want to preserve the error chain for logging and debugging
arg...(String | VErrorOptions | Error)? sprintf args, options or causeargs...String? sprintf args
A string representing the WError.
Returns String string representation
For purely historical reasons, WError's cause() function allows you to set the cause.
cError cause