Skip to main content
Home

Provides enhanced custom errors with a stackTrace, code, and target properties.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
94%
Published
a year ago (0.3.0)

@gnome/errors

logo Work less. Do more.

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.
  • stackTrace property to get the stack trace as an array of strings.
  • code property to get or set the error code.
  • target property 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

  • AbortError an error for aborting an operation.
  • ArgumentEmptyError an error for when a strings and collections. For strings, it is null, empty, or whitespace or for empty collections.
  • ArgumentError thrown when a argument vailes validation.]
  • ArgumentNullError thrown when an argument is null or undefined.
  • ArgumentRangeError thrown when an argument is out of range.
  • FormatError thrown when a value can not be formatted such as conversions to strings.
  • InvalidCastError thrown when a value can not be converted into the desired value.
  • InvalidOperationError thrown when an operation can not be or should not be executed.
  • NotImplementedError thrown when a method or function is not implemented.
  • NotSupportedError thrown when a use case is not supproted such as a function that only works on linux.
  • NullReferenceError thrown when value is unexpectedly null or undefined
  • ObjectDisposedError thrown when an object is already disposed and a member is accessed.
  • TimeoutError thrown when a operation times out.

MIT License

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@gnome/errors

Import symbol

import * as errors from "@gnome/errors";
or

Import directly with a jsr specifier

import * as errors from "jsr:@gnome/errors";

Add Package

pnpm i jsr:@gnome/errors
or (using pnpm 10.8 or older)
pnpm dlx jsr add @gnome/errors

Import symbol

import * as errors from "@gnome/errors";

Add Package

yarn add jsr:@gnome/errors
or (using Yarn 4.8 or older)
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";