Skip to main content
Home

Built and signed on GitHub Actions

Works with
This package works with Node.js, DenoIt is unknown whether this package works with Cloudflare Workers, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score100%
Downloads52/wk
Publisheda year ago (0.0.3)

A collection of the most common exceptions used across kz packages, adapted for API consistency and case-coverage, exhaustively tested, and documented thoroughly.

kz logo common-exceptions

kz is a library providing heavily tested and documented features with consistent and predictable APIs designed to simplify the development and maintenance of complex, performant, and scalable Deno applications.

@kz/common-exceptions

The @kz/common-exceptions module provides commonly used exceptions with intuitive APIs.

Overview | API Docs

All exceptions begin with the Exception base class, accepting a message, and optional exception data. All exceptions have a single common exception data property, cause, which acts as the inner exception or error, if one was unable to be handled gracefully. Any data that is deemed relevant to the exception can be added to the exception data, though some exceptions have named data properties which are especially relevant.

import { Exception, KeyException } from './mod.ts';

const keyExc = new KeyException(
  `The 'name' key does not exist.`,
  {
    id: '82hffd03',
    action: 'hfjkdhak',
    key: 'key', //named property
  },
);
const msg = `The 'name' key does not exist.`;

console.assert(keyExc instanceof KeyException); // ✔
console.assert(keyExc instanceof Exception); // ✔
console.assert(keyExc.message === msg); // ✔

When a message is provided, the exception data is simply along for the ride, useful where developers see fit. Some exceptions can also accept only exception data, of which the named data properties are used to construct the exception message. For integereleven-created exceptions, they also provide insight to the exception explainer tool.

import { KeyException } from './mod.ts';

const keyExc = new KeyException({
  key: 'name',
  validKeys: ['first', 'last'],
});

const expected =
  'Unable to locate a property key, name, on an object. Valid property keys include: first, last.';

console.assert(keyExc.message === expected); // ✔

Exceptions are created in a hierarchy, and those on the outer branches have the generated message functionality. We use the hierarchy to provide better exception handling.

Contributing

Contributions are welcome! Take a look at our contributing guidelines to get started.

Contributor Covenant

License

The MIT License (MIT) 2022 integereleven. Refer to LICENSE for details.

Built with ❤ by integereleven

kz.io logo

GitHub commit activity GitHub issues

Built and signed on
GitHub Actions

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:@kz/common-exceptions

Import symbol

import * as common_exceptions from "@kz/common-exceptions";
or

Import directly with a jsr specifier

import * as common_exceptions from "jsr:@kz/common-exceptions";

Add Package

pnpm i jsr:@kz/common-exceptions
or (using pnpm 10.8 or older)
pnpm dlx jsr add @kz/common-exceptions

Import symbol

import * as common_exceptions from "@kz/common-exceptions";

Add Package

yarn add jsr:@kz/common-exceptions
or (using Yarn 4.8 or older)
yarn dlx jsr add @kz/common-exceptions

Import symbol

import * as common_exceptions from "@kz/common-exceptions";

Add Package

vlt install jsr:@kz/common-exceptions

Import symbol

import * as common_exceptions from "@kz/common-exceptions";

Add Package

npx jsr add @kz/common-exceptions

Import symbol

import * as common_exceptions from "@kz/common-exceptions";

Add Package

bunx jsr add @kz/common-exceptions

Import symbol

import * as common_exceptions from "@kz/common-exceptions";