Socket
Socket
Sign inDemoInstall

@blackglory/errors

Package Overview
Dependencies
4
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @blackglory/errors

Common errors


Version published
Weekly downloads
1.4K
increased by178.78%
Maintainers
1
Install size
725 kB
Created
Weekly downloads
 

Changelog

Source

3.0.3 (2023-06-10)

Bug Fixes

  • export src (be0619b)

Readme

Source

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>

FAQs

Last updated on 10 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc