latest
gnomejs/sdkProvides enhanced custom errors with a stackTrace, code, and target properties.
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




JSR Score
94%
Published
a year ago (0.3.0)
@gnome/errors
Overview
All errors in @gnome will inherit from SystemError
The errors module extends the built-in Error class to provide additional functionality such as:
toObject()method to convert an error to JSON object.set()method to set multiple properties of the error.stackTraceproperty to get the stack trace as an array of strings.codeproperty to get or set the error code.targetproperty to get or set the target of the error such as the name of the method that threw the error.
The module also provides a number of error classes that extend and utility functions to work with errors:
collect()function to collect all the errors from an error object.walk()function to walk through an error and its inner errors.printError()function to print an error to the console.
Basic Usage
import { SystemError } from '@gnome/errors' try { throw new SystemError("message"); } catch (e) { console.log(e.stackTrace) console.log(e.code) }
Errors
AbortErroran error for aborting an operation.ArgumentEmptyErroran error for when a strings and collections. For strings, it is null, empty, or whitespace or for empty collections.ArgumentErrorthrown when a argument vailes validation.]ArgumentNullErrorthrown when an argument isnullorundefined.ArgumentRangeErrorthrown when an argument is out of range.FormatErrorthrown when a value can not be formatted such as conversions to strings.InvalidCastErrorthrown when a value can not be converted into the desired value.InvalidOperationErrorthrown when an operation can not be or should not be executed.NotImplementedErrorthrown when a method or function is not implemented.NotSupportedErrorthrown when a use case is not supproted such as a function that only works on linux.NullReferenceErrorthrown when value is unexpectedlynullorundefinedObjectDisposedErrorthrown when an object is already disposed and a member is accessed.TimeoutErrorthrown when a operation times out.
Add Package
deno add jsr:@gnome/errors
Import symbol
import * as errors from "@gnome/errors";
Import directly with a jsr specifier
import * as errors from "jsr:@gnome/errors";
Add Package
pnpm i jsr:@gnome/errors
pnpm dlx jsr add @gnome/errors
Import symbol
import * as errors from "@gnome/errors";
Add Package
yarn add jsr:@gnome/errors
yarn dlx jsr add @gnome/errors
Import symbol
import * as errors from "@gnome/errors";
Add Package
vlt install jsr:@gnome/errors
Import symbol
import * as errors from "@gnome/errors";
Add Package
npx jsr add @gnome/errors
Import symbol
import * as errors from "@gnome/errors";
Add Package
bunx jsr add @gnome/errors
Import symbol
import * as errors from "@gnome/errors";