パッケージの詳細

@blackglory/errors

BlackGlory16.8kMIT3.0.3

Common errors

readme

errors

Common errors.

Install

npm install --save @blackglory/errors
# or
yarn add @blackglory/errors

API

type CustomErrorConstructor<T extends CustomError = CustomError> =
  new (message?: string) => T

interface SerializableError {
  name: string
  message: string
  stack: string | null
  ancestors: string[]
}

CustomError

class CustomError extends Error {}

CustomError has better default behaviors than Error:

  • console.error prints the correct exception name, not Error.
  • instanceof operator matches based on names rather than inheritance relationships, which helps SerializableError instanceof CustomError.

AssertionError

class AssertionError extends CustomError {}

isError

function isError(val: unknown): val is Error
function isntError<T>(val: T): val is Exclude<T, Error>

normalize

function normalize(err: Error): SerializableError

hydrate

function hydrate(err: SerializableError): Error

isSerializableError

function isSerializableError(val: unknown): val is SerializableError

assert

/**
 * @throws {AssertionError}
 */
function assert(condition: unknown, message?: string): asserts condition

getErrorNames

function getErrorNames(err: Error | SerializableError): Iterable<string>

traverseErrorPrototypeChain

function traverseErrorPrototypeChain(err: Error): Iterable<Error>

更新履歴

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.0.3 (2023-06-10)

Bug Fixes

3.0.2 (2023-04-05)

3.0.1 (2023-04-05)

Bug Fixes

  • add missing dependencies (c62f767)

3.0.0 (2023-01-22)

⚠ BREAKING CHANGES

  • CommonJS => ESM

  • commonjs => esm (bee388c)

2.4.3 (2023-01-21)

Bug Fixes

  • remove iterable-operator dependency (ab7106d)
  • remove iterable-operator dependency (857f19f)

2.4.2 (2023-01-21)

2.4.1 (2022-12-18)

2.4.0 (2022-12-18)

Features

  • add default value for assert (6349c14)

2.3.0 (2022-11-07)

Features

Bug Fixes

2.2.3 (2022-10-24)

2.2.2 (2022-08-01)

2.2.1 (2022-03-19)

2.2.0 (2022-02-10)

Features

2.1.0 (2022-01-27)

Features

2.0.0 (2022-01-11)

⚠ BREAKING CHANGES

    • Remove refute, ExpectedError

Features

  • the parameter message is now required (51d9350)

1.1.2 (2021-02-04)

Bug Fixes

1.1.1 (2021-02-03)

1.1.0 (2021-02-03)

Features

  • add assert, refute, AssertionError (52baf47)

1.0.0 (2021-02-03)

Features

0.1.5 (2021-02-03)

Features

0.1.4 (2021-01-20)

Bug Fixes

0.1.3 (2021-01-04)

Bug Fixes

0.1.2 (2020-12-16)

Features

0.1.1 (2020-12-16)

Features

  • add CustomErrorConstructor (bf3bf02)

0.1.0 (2020-12-16)

Features