p-error
The error module provides functions for creating and inspecting JavaScript errors.
use p-error as eCreate Errors
Section titled “Create Errors”create[message]
Section titled “create[message]”Creates a generic Error.
type[message]
Section titled “type[message]”Creates a TypeError.
range[message]
Section titled “range[message]”Creates a RangeError.
reference[message]
Section titled “reference[message]”Creates a ReferenceError.
syntax[message]
Section titled “syntax[message]”Creates a SyntaxError.
uri[message]
Section titled “uri[message]”Creates a URIError.
wrap[message; cause]
Section titled “wrap[message; cause]”Creates an Error with a cause (for error chaining).
use p-error as ethrow e.create[///something went wrong///]throw e.type[///expected a string///]throw e.range[///index out of bounds///]
-- Error chainingtry riskyOperation[]catch err throw e.wrap[///operation failed///; err]Inspect Errors
Section titled “Inspect Errors”iserror[val]
Section titled “iserror[val]”Returns true if val is an instance of Error.
message[err]
Section titled “message[err]”Returns the error message. If err is not an Error, returns String(err).
name[err]
Section titled “name[err]”Returns the error name (e.g. "TypeError", "RangeError"). Returns "Error" for non-Error values.
stack[err]
Section titled “stack[err]”Returns the stack trace as a string. Returns "" for non-Error values.
cause[err]
Section titled “cause[err]”Returns the error’s cause (if set via wrap or the cause option).
use p-error as econst err be e.type[///invalid argument///]e.iserror[err] -- truee.message[err] -- "invalid argument"e.name[err] -- "TypeError"e.stack[err] -- "TypeError: invalid argument\n at ..."
const wrapped be e.wrap[///failed///; err]e.cause[wrapped] -- the original TypeErrore.message[wrapped] -- "failed"