@kz/common-exceptions@0.0.3Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
A collection of the most common exceptions used across kz packages, adapted for API consistency and case-coverage, exhaustively tested, and documented thoroughly.
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.
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.
License
The MIT License (MIT) 2022 integereleven. Refer to LICENSE for details.
Built with ❤ by integereleven
Add Package
deno add jsr:@kz/common-exceptions
Import symbol
import * as common_exceptions from "@kz/common-exceptions";
Import directly with a jsr specifier
import * as common_exceptions from "jsr:@kz/common-exceptions";
Add Package
pnpm i jsr:@kz/common-exceptions
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
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";