Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
ts-nested-error
Advanced tools
Lightweight xplatform nested error implementation with native TypeScript support.
Super lightweight crossplatform (browser compatible) dependency-free nested error implementation.
new NestedError(message: string, public readonly innerError?: Error)
Class that provides readonly innerError?: Error
property alongside with an error callstack (as .stack
property) of original error eagerly
combined with itself's. Deeply nested errors
form a list of callstacks and error messages that are concatenated.
Example:
try {
throw new Error('Connection timed out');
} catch (err) {
throw new NestedError(`Oh no, couldn't load file! More info in inner error`, err);
}
This code will produce an error that when stringifed shows the following message:
NestedError: Oh no, couldn't load file! More info in inner error
at someMethod (/path/to/code.js:line:column)
at ...
======= INNER ERROR =======
Error: Connection timed out
at someMethod (/path/to/code.js:line:column)
at ...
NestedError.rethrow(message: string)
Returns a function that throws NestedError
or an object
of class that is derived from it with the given message
.
This is mostly intended to be a shorthand to create error wrapping callbacks
for Promise
s:
import { NestedError } from 'ts-nested-error';
class DbError extends NestedError {}
database.get().then(
data => console.log(`Hooray! data: ${data}`),
DbError.rethrow('some database error happened') // throws instanceof DbError
);
toError(err)
Returns err
itself if err instanceof Error === true
, otherwise attemts to
stringify it and wrap into Error
object to be returned.
const err = new Error('oops');
// noop if err instanceof Error
toError(err) === err;
// wrapped 42 into Error with warning message
(toError(42) instanceof Error) === true;
toError('non-error value').message === `Value that is not an instance of Error was thrown: non-error value`
FAQs
Lightweight xplatform nested error implementation with native TypeScript support.
The npm package ts-nested-error receives a total of 368 weekly downloads. As such, ts-nested-error popularity was classified as not popular.
We found that ts-nested-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.