errlop
Version:
An extended Error class that envelops a parent error, such that the stack trace contains the causation
63 lines • 2.72 kB
TypeScript
/** A valid Errlop or Error instance. */
export type ErrorValid = Errlop | Error;
/** Properties {@link Errlop} supports. */
export interface ErrorProperties {
/** The description of this error. */
message: string;
/** The code to identify this error. If a string code, it will be included in the stack. */
code: string | number;
/** The severity level of this error. */
level: string | number;
/** The parent that caused this error, if any. If not provided, inherited from `cause` property. */
parent: ErrorValid | null;
/** An array of the {@link parent} lineage. Most immediate to most distant. */
ancestors: Array<ErrorValid>;
/** A numeric code that can be used for the process exit status. If not provided, inherited from {@link ancestors} `exitCode`, `errno`, `code` numeric properties. */
exitCode: number | null;
/** The stack of this error alone, without any ancestry. */
orphanStack: string;
/** The stack of this error including its ancestry. */
stack: string;
}
/** An input that can become an Errlop or Error instance. */
export type ErrorInput = Errlop | Error | Partial<ErrorProperties> | string | any;
/** Errlop, an extended Error class that envelops a parent Error to provide ancestry stack inforation. */
export default class Errlop extends Error implements ErrorProperties {
parent: ErrorValid | null;
ancestors: Array<ErrorValid>;
exitCode: number | null;
orphanStack: string;
stack: string;
message: string;
code: string | number;
level: string | number;
/** Duck typing so native classes can work with transpiled classes, as otherwise they would fail instanceof checks. */
klass: typeof Errlop;
/**
* Turn the input and parent into an Errlop instance.
* @param input
* @param parent
*/
constructor(input: ErrorInput, parent?: ErrorInput);
/** The separator to use for the stack entries */
static stackSeparator: string;
/** Check whether or not the value is an Errlop instance */
static isErrlop(value: Errlop): true;
static isErrlop(value?: any): value is Errlop;
/** Check whether or not the value is an Errlop or Error instance. */
static isError(value: ErrorValid): true;
static isError(value?: any): value is ErrorValid;
/**
* Ensure that the value is an Errlop instance
* @param value
*/
static ensure(value: ErrorInput): Errlop;
/**
* Syntactic sugar for Errlop class creation.
* Enables `Errlop.create(...)` to achieve `new Errlop(...)`
* @param input
* @param parent
*/
static create(input: ErrorInput, parent?: ErrorInput): Errlop;
}
//# sourceMappingURL=index.d.ts.map