0.3.0 • Published 5 years ago
@perfective/error v0.3.0
Error
The @perfective/error package helps organize exceptions and error handling.
It defines an Exception, based on the JS
Error class,
that supports localizable error messages and error chaining;
and provides functions to handle error stack output.
Read the full documentation in the repository.
Exception:Exception.toString()— outputs the stack of all error messages.exception(message: string, tokens: ExceptionTokens = {}, context: ExceptionContext = {}): Exception— creates anExceptionwithout a previous error.causedBy(previous: Error, message: string, tokens: ExceptionTokens = {}, context: ExceptionContext = {}): Exception— creates anExceptionwith a previous error.unknownError(error: unknown): Error | Exception— returns a passedErroror creates a newLiteral errorException.isException<T>(value: Exception | T): value is Exception— returnstruewhen value is anException.isNotException<T>(value: Exception | T): value is T— returnstruewhen value is not anException.chainStack(error: Error): string— outputs the stack of all errors with their stack trace.fault(error: Error): Error— returns the first error in the chain.
ExceptionMessage:exceptionMessage(template: string, tokens?: ExceptionTokens): ExceptionMessage— creates anExceptionMessagewith an empty tokens object if the argument not provided.exceptionMessageOutput(message: ExceptionMessage): string— creates a string to output anExceptionMessage.
Failure— a record type to serialize errors and exceptions:failure<E extends Error>(error: E): Failure— convert andErroror anExceptioninto aFailurerecord.
- Throwing errors:
throws<E extends Error>(error: E): never— throws a provided error.throws<E extends Error>(error: () => E): never— throws an error created by the provided function.throws<E extends Error>(message: string, context: ExceptionContext = {}): never— creates and throws anExceptionwith the givenmessageandcontext.rethrows(previous: Error, message: string, context: ExceptionContext = {}): never— creates and throws an exception with the givenmessage,context, andpreviouserror.Panic— a type of nullary functions that throw an error when executed:panic<E extends Error>(error: E): Panic— creates a function that throws a provided error.panic<E extends Error>(error: () => E): Panic— creates a function that throws an error created by the provided function. *panic<E extends Error>(message: string, context: ExceptionContext = {}): Panic— creates a function that throws anExceptionwith the givenmessageandcontext.Rethrow<E extends Error = Error>— a type of unary functions that rethrow a previous error when executed: *rethrow(message: string, context: ExceptionContext = {}): Rethrow— creates a function that throws an exception with the givenmessage,context, andpreviouserror.
Error:error(message?: string): Error— instantiates a newError.isError<T>(value: Error | T): value is Error— returnstruewhen the value is an instance ofError.isNotError<T>(value: Error | T): value is T— returnstruewhen the value is not an instance ofError.
EvalError:evalError(message?: string): EvalError— instantiates a newEvalError.isEvalError<T>(value: EvalError | T): value is EvalError— returnstruewhen the value is an instance ofEvalError.isNotEvalError<T>(value: EvalError | T): value is T— returnstruewhen the value is not an instance ofEvalError.
RangeError:rangeError(message?: string): RangeError— instantiates a newRangeError.isRangeError<T>(value: RangeError | T): value is RangeError— returnstruewhen the value is an instance ofRangeError.isNotRangeError<T>(value: RangeError | T): value is T— returnstruewhen the value is not an instance ofRangeError.
ReferenceError:referenceError(message?: string): ReferenceError— instantiates a newReferenceError.isReferenceError<T>(value: ReferenceError | T): value is ReferenceError— returnstruewhen the value is an instance ofReferenceError.isNotReferenceError<T>(value: ReferenceError | T): value is T— returnstruewhen the value is not an instance ofReferenceError.
SyntaxError:syntaxError(message?: string): SyntaxError— instantiates a newSyntaxError.isSyntaxError<T>(value: SyntaxError | T): value is SyntaxError— returnstruewhen the value is an instance ofSyntaxError.isNotSyntaxError<T>(value: SyntaxError | T): value is T— returnstruewhen the value is not an instance ofSyntaxError.
TypeError:typeError(message?: string): TypeError— instantiates a newTypeError.isTypeError<T>(value: TypeError | T): value is TypeError— returnstruewhen the value is an instance ofTypeError.isNotTypeError<T>(value: TypeError | T): value is T— returnstruewhen the value is not an instance ofTypeError.
0.3.0
5 years ago
0.2.4
5 years ago
0.2.3
5 years ago
0.2.2
5 years ago
0.2.1
5 years ago
0.2.0
5 years ago
0.2.0-beta
5 years ago
0.2.0-alpha.4
5 years ago
0.2.0-alpha.3
5 years ago
0.2.0-alpha.2
5 years ago
0.2.0-alpha.1
5 years ago
0.2.0-alpha
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago