{"id":19584840,"url":"https://github.com/flex-development/errnode","last_synced_at":"2026-05-17T03:34:49.386Z","repository":{"id":65137205,"uuid":"582459410","full_name":"flex-development/errnode","owner":"flex-development","description":"Universal API for creating Node.js errors","archived":false,"fork":false,"pushed_at":"2024-04-23T06:36:35.000Z","size":2431,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-01T09:40:36.302Z","etag":null,"topics":["errno","error","node","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/flex-development/errnode","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flex-development.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["flex-development"]}},"created_at":"2022-12-26T22:49:15.000Z","updated_at":"2024-08-25T23:55:21.765Z","dependencies_parsed_at":"2023-09-29T08:08:52.054Z","dependency_job_id":"13e32c61-6ece-453e-8aa7-0621c6d0dfaa","html_url":"https://github.com/flex-development/errnode","commit_stats":{"total_commits":185,"total_committers":2,"mean_commits":92.5,"dds":0.2810810810810811,"last_synced_commit":"4d7512952fab90b864505b3aa1ffe37a683a73cd"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Ferrnode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Ferrnode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Ferrnode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flex-development%2Ferrnode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flex-development","download_url":"https://codeload.github.com/flex-development/errnode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240858536,"owners_count":19868997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["errno","error","node","nodejs","typescript"],"created_at":"2024-11-11T07:50:17.876Z","updated_at":"2026-05-17T03:34:44.352Z","avatar_url":"https://github.com/flex-development.png","language":"TypeScript","funding_links":["https://github.com/sponsors/flex-development"],"categories":[],"sub_categories":[],"readme":"# errnode\n\n[![github release](https://img.shields.io/github/v/release/flex-development/errnode.svg?include_prereleases\\\u0026sort=semver)](https://github.com/flex-development/errnode/releases/latest)\n[![npm](https://img.shields.io/npm/v/@flex-development/errnode.svg)](https://npmjs.com/package/@flex-development/errnode)\n[![codecov](https://codecov.io/gh/flex-development/errnode/graph/badge.svg?token=e2gnycTeI9)](https://codecov.io/gh/flex-development/errnode)\n[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)\n[![license](https://img.shields.io/github/license/flex-development/errnode.svg)](LICENSE.md)\n[![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits\\\u0026logoColor=ffffff)](https://conventionalcommits.org)\n[![typescript](https://img.shields.io/badge/-typescript-3178c6?logo=typescript\\\u0026logoColor=ffffff)](https://typescriptlang.org)\n[![vitest](https://img.shields.io/badge/-vitest-6e9f18?style=flat\\\u0026logo=vitest\\\u0026logoColor=ffffff)](https://vitest.dev)\n[![yarn](https://img.shields.io/badge/-yarn-2c8ebb?style=flat\\\u0026logo=yarn\\\u0026logoColor=ffffff)](https://yarnpkg.com)\n\nUniversal API for creating [Node.js errors][errors]\n\n## Contents\n\n- [What is this?](#what-is-this)\n- [When should I use this?](#when-should-i-use-this)\n- [Install](#install)\n- [Use](#use)\n- [API](#api)\n  - [`E`](#ecode-base-message)\n  - [`codes`](#codes)\n  - [`determineSpecificType(value)`](#determinespecifictypevalue)\n  - [`errors`](#errors)\n  - [`formatList(list[, type])`](#formatlistlist-type)\n  - [`hideStackFrames(fn)`](#hidestackframesfn)\n  - [`isNodeError(value)`](#isnodeerrorvalue)\n  - [`syscodes`](#syscodes)\n- [Types](#types)\n  - [`Code`](#code)\n  - [`ErrnoException\u003c[T]\u003e`](#errnoexceptiont)\n  - [`MessageFn\u003c[T][, Args]\u003e`](#messagefnt-args)\n  - [`NodeErrorConstructor\u003c[T][, Args]\u003e`](#nodeerrorconstructort-args)\n  - [`NodeErrorMap`](#nodeerrormap)\n  - [`NodeError\u003c[T]\u003e`](#nodeerrort)\n  - [`Stringifiable`](#stringifiable)\n  - [`SystemCode`](#systemcode)\n  - [`SystemErrorMap`](#systemerrormap)\n- [Contribute](#contribute)\n\n## What is this?\n\nThis package provides a universal API for creating [Node.js errors][errors].\n\n## When should I use this?\n\nThis package is designed to help developers build [ponyfills][ponyfill], as well as more verbose tools like\n[`mlly`][mlly], by providing a set of utilities and constructor functions for creating [Node.js errors][errors].\n\n## Install\n\nThis package is [ESM only][esm].\n\nIn Node.js (version 18+) with [yarn][]:\n\n```sh\nyarn add @flex-development/errnode\n```\n\n\u003cblockquote\u003e\n  \u003csmall\u003e\n    See \u003ca href='https://yarnpkg.com/protocol/git'\u003eGit - Protocols | Yarn\u003c/a\u003e\n    \u0026nbsp;for details regarding installing from Git.\n  \u003c/small\u003e\n\u003c/blockquote\u003e\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```ts\nimport { ERR_MODULE_NOT_FOUND } from 'https://esm.sh/@flex-development/errnode'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { ERR_MODULE_NOT_FOUND } from 'https://esm.sh/@flex-development/errnode'\n\u003c/script\u003e\n```\n\n## Use\n\nSay we have the file [`example.mjs`](./example.mjs):\n\n```ts\nimport { ERR_INVALID_ARG_TYPE, isNodeError } from '@flex-development/errnode'\n\n/**\n * Ensure `value` is a string.\n *\n * @see {@linkcode ErrInvalidArgType}\n *\n * @param {unknown} value\n *  Value supplied by user\n * @param {string} name\n *  Name of invalid argument or property\n * @return {value is string}\n *  `true` if `value` is a string\n * @throws {import('@flex-development/errnode').ErrInvalidArgType}\n *  If `value` is not a string\n */\nfunction validateString(value, name) {\n  if (typeof value === 'string') return true\n  throw new ERR_INVALID_ARG_TYPE(name, 'string', value)\n}\n\ntry {\n  validateString(null, 'path')\n} catch (e) {\n  console.log('isNodeError:', isNodeError(e))\n  console.log('TypeError:', e instanceof TypeError, '\\n')\n  throw e\n}\n```\n\n...running `node example.mjs` yields:\n\n```sh\nisNodeError: true\nTypeError: true\n\nfile:///node_modules/@flex-development/errnode/dist/internal/stack-trace.mjs:9\n  Error.captureStackTrace(error);\n        ^\n\nTypeError: The 'path' argument must be of type string. Received null\n    at __node_internal_captureLargerStackTrace (file:///node_modules/@flex-development/errnode/dist/internal/stack-trace.mjs:9:9)\n    at new NodeError (file:///node_modules/@flex-development/errnode/dist/e.mjs:50:45)\n    at validateString (file:///example.mjs:19:9)\n    at file:///example.mjs:23:3\n    at ModuleJob.run (node:internal/modules/esm/module_job:234:25)\n    at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)\n    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5) {\n  code: 'ERR_INVALID_ARG_TYPE'\n}\n```\n\n## API\n\nThis package exports the following identifiers:\n\n- [`E`](#ecode-base-message)\n- [`codes`](#codes)\n- [`determineSpecificType`](#determinespecifictypevalue)\n- [`errors`](#errors)\n  - `ERR_ARG_NOT_ITERABLE`\n  - `ERR_ENCODING_NOT_SUPPORTED`\n  - `ERR_IMPORT_ASSERTION_TYPE_FAILED`\n  - `ERR_IMPORT_ASSERTION_TYPE_MISSING`\n  - `ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED`\n  - `ERR_IMPORT_ATTRIBUTE_MISSING`\n  - `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE`\n  - `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED`\n  - `ERR_INCOMPATIBLE_OPTION_PAIR`\n  - `ERR_INVALID_ARG_TYPE`\n  - `ERR_INVALID_ARG_VALUE`\n  - `ERR_INVALID_FILE_URL_HOST`\n  - `ERR_INVALID_FILE_URL_PATH`\n  - `ERR_INVALID_MODULE_SPECIFIER`\n  - `ERR_INVALID_PACKAGE_CONFIG`\n  - `ERR_INVALID_PACKAGE_TARGET`\n  - `ERR_INVALID_RETURN_VALUE`\n  - `ERR_INVALID_THIS`\n  - `ERR_INVALID_TUPLE`\n  - `ERR_INVALID_URL_SCHEME`\n  - `ERR_INVALID_URL`\n  - `ERR_METHOD_NOT_IMPLEMENTED`\n  - `ERR_MISSING_ARGS`\n  - `ERR_MISSING_OPTION`\n  - `ERR_MODULE_NOT_FOUND`\n  - `ERR_NETWORK_IMPORT_DISALLOWED`\n  - `ERR_NO_CRYPTO`\n  - `ERR_NO_ICU`\n  - `ERR_OPERATION_FAILED`\n  - `ERR_PACKAGE_IMPORT_NOT_DEFINED`\n  - `ERR_PACKAGE_PATH_NOT_EXPORTED`\n  - `ERR_UNHANDLED_ERROR`\n  - `ERR_UNKNOWN_BUILTIN_MODULE`\n  - `ERR_UNKNOWN_ENCODING`\n  - `ERR_UNKNOWN_FILE_EXTENSION`\n  - `ERR_UNKNOWN_MODULE_FORMAT`\n  - `ERR_UNSUPPORTED_DIR_IMPORT`\n  - `ERR_UNSUPPORTED_ESM_URL_SCHEME`\n  - `ERR_UNSUPPORTED_RESOLVE_REQUEST`\n- [`formatList`](#formatlistlist-type)\n- [`hideStackFrames`](#hidestackframesfn)\n- [`isNodeError`](#isnodeerrorvalue)\n- [`syscodes`](#syscodes)\n\nThere is no default export.\n\n### Errors\n\nConstructor functions representing [Node.js error codes][nodejs-error-codes]. Constructor arguments are used to build\nerror messages.\n\nErrors (and their types) can be imported individually:\n\n```ts\nimport {\n  ERR_INVALID_MODULE_SPECIFIER,\n  ERR_INVALID_PACKAGE_CONFIG,\n  ERR_INVALID_PACKAGE_TARGET,\n  ERR_MODULE_NOT_FOUND,\n  ERR_PACKAGE_IMPORT_NOT_DEFINED,\n  ERR_PACKAGE_PATH_NOT_EXPORTED,\n  ERR_UNSUPPORTED_DIR_IMPORT,\n  type ErrInvalidModuleSpecifier,\n  type ErrInvalidModuleSpecifierArgs,\n  type ErrInvalidModuleSpecifierConstructor,\n  type ErrInvalidPackageConfig,\n  type ErrInvalidPackageConfigArgs,\n  type ErrInvalidPackageConfigConstructor,\n  type ErrInvalidPackageTarget,\n  type ErrInvalidPackageTargetArgs,\n  type ErrInvalidPackageTargetConstructor,\n  type ErrModuleNotFound,\n  type ErrModuleNotFoundArgs,\n  type ErrModuleNotFoundConstructor,\n  type ErrPackageImportNotDefined,\n  type ErrPackageImportNotDefinedArgs,\n  type ErrPackageImportNotDefinedConstructor,\n  type ErrPackagePathNotExported,\n  type ErrPackagePathNotExportedArgs,\n  type ErrPackagePathNotExportedConstructor,\n  type ErrUnsupportedDirImport,\n  type ErrUnsupportedDirImportConstructor\n } from '@flex-development/errnode'\n```\n\n...or all at once using the `errors` export:\n\n```ts\nimport { errors } from '@flex-development/errnode'\n```\n\nSee the [source code](./src/errors) for documentation.\n\n**Note**: This package **does not export a constructor for every error**. Submit a feature request (or pull request if\nyou're up for the challenge \\:wink:) to add a constructor.\n[`E`](#ecode-base-message) can be used instead, however.\n\n### `E(code, Base, message)`\n\nCreate a Node.js error constructor.\n\nConstructor arguments are passed to [`format`][format] if the error `message` is a string, or `message` itself if it is\na function. Message functions are also called with the new Node.js error instance as `this`.\n\n#### Signatures\n\n```ts\nfunction E\u003cT extends NodeErrorConstructor\u003e(\n  code: T['prototype']['code'],\n  Base: ErrorConstructor,\n  message: MessageFn\u003cT['prototype'], Parameters\u003cT\u003e\u003e | string\n): T\n\nfunction E\u003cT extends NodeError, Args extends any[] = any[]\u003e(\n  code: T['code'],\n  Base: ErrorConstructor,\n  message: MessageFn\u003cT, Args\u003e\n): NodeErrorConstructor\u003cT, Args\u003e\n```\n\n#### Parameters\n\n- `code` ([`Code`](#code))\n  — error code\n- `Base` (`ErrorConstructor`)\n  — base class\n- `message` ([`MessageFn`](#messagefnt-args) | `string`)\n  — error message string or function\n\n#### Returns\n\n([`NodeErrorConstructor`](#nodeerrorconstructort-args)) [`NodeError`](#nodeerrort) constructor.\n\n### `codes`\n\nNode.js error codes.\n\nSee [`NODE_VERSIONS`](./__tests__/utils/node-versions.ts) for a list of supported Node.js versions.\n\n### `determineSpecificType(value)`\n\nDetermine the specific type of a value for type-mismatch errors.\n\n#### Parameters\n\n- `value` (`unknown`)\n  — value to check\n\n#### Returns\n\n(`string`) specific type of `value`.\n\n### `formatList(list[, type])`\n\nCreate a list string in the form `'A and B'` or `'A, B, ..., and Z`.\n\n#### Parameters\n\n- `list` (`string | readonly string[]`)\n  — list to format\n- `type` (`'and' | 'or' | null | undefined`, optional)\n  — list transition type to insert before last element\n  - **default**: `'and'`\n\n#### Returns\n\n(`string`) formatted list.\n\n### `hideStackFrames(fn)`\n\nRemove unnecessary frames from Node.js core errors.\n\n#### Type Parameters\n\n- `T` ([`Fn`][fn])\n  — function to wrap\n\n#### Parameters\n\n- `fn` (`T`)\n  — function to wrap\n\n#### Returns\n\n(`T`) the wrapped function.\n\n### `isNodeError(value)`\n\nCheck if `value` is a [`NodeError`](#nodeerrort).\n\n#### Parameters\n\n- `value` (`unknown`)\n  — value to check\n\n#### Returns\n\n(`value is NodeError`) `true` if `value` is `NodeError`, `false` otherwise.\n\n### `syscodes`\n\nSystem error codes.\n\nSee [`NODE_VERSIONS`](./__tests__/utils/node-versions.ts) for a list of supported Node.js versions.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\n\n### `Code`\n\nUnion of registered codes that can occur where a node error code is expected (TypeScript type).\n\nTo register new codes, augment [`NodeErrorMap`](#nodeerrormap). They will be added to this union automatically.\n\n```ts\ntype Code = Extract\u003ckeyof NodeErrorMap, string\u003e\n```\n\n### `ErrnoException\u003c[T]\u003e`\n\nNode.js exception object (TypeScript interface).\n\n#### Type Parameters\n\n- `T` ([`SystemCode`](#systemcode), optional)\n  — system error code\n  - **default**: `SystemCode`\n\n#### Extends\n\n- `Error`\n\n#### Properties\n\n- `code` (`T`)\n  — system error code\n- `errno` (`number`)\n  — libuv error number\n- `message` (`string`)\n  — error message, always prefixed by `syscall` and `code`\n- `path?` (`string | undefined`)\n  — relevant invalid pathname\n- `syscall` (`string`)\n  — failed [syscall][] description\n\n### `MessageFn\u003c[T][, Args]\u003e`\n\nBuild an error message.\n\n#### Type Parameters\n\n- `T` ([`NodeError`](#nodeerrort), optional)\n  — node error\n  - **default**: `NodeError`\n- `Args` (`readonly any[]`, optional)\n  — message arguments\n  - **default**: `any[]`\n\n#### Parameters\n\n- `this` (`T`)\n  — node error object\n- `...args` (`Args`)\n  — message arguments\n\n#### Returns\n\n(`string`) error message.\n\n### `NodeErrorConstructor\u003c[T][, Args]\u003e`\n\nNode.js error constructor (TypeScript interface).\n\n#### Type Parameters\n\n- `T` ([`NodeError`](#nodeerrort), optional)\n  — node error\n  - **default**: `NodeError`\n- `Args` (`readonly any[]`, optional)\n  — message arguments\n  - **default**: `any[]`\n\n#### Signatures\n\n- `new (...args: Args): T`\n- `(...args: Args): T`\n\n#### Properties\n\n- `prototype` (`T`)\n  — node.js error prototype\n\n### `NodeErrorMap`\n\nRegistry of Node.js error codes (TypeScript interface).\n\nWhen developing utilities that use more codes, augment `NodeErrorMap` to register those codes:\n\n```ts\ndeclare module '@flex-development/errnode' {\n  interface NodeErrorMap {\n    ERR_CUSTOM: true\n  }\n}\n```\n\n### `NodeError\u003c[T]\u003e`\n\nNode.js error object (TypeScript interface).\n\n#### Type Parameters\n\n- `T` ([`Code`](#code), optional)\n  — error code\n  - **default**: `Code`\n\n#### Extends\n\n- `Error`\n\n#### Properties\n\n- `code` (`T`)\n  — error code\n- `toString` (`() =\u003e string`)\n  — get a string representation of the error\n\n### `Stringifiable`\n\nA value with a `toString` method (TypeScript interface).\n\n#### Properties\n\n- `toString` (`() =\u003e string`)\n  — get a string representation of the value\n\n### `SystemCode`\n\nUnion of registered codes that can occur where a system error code is expected (TypeScript type).\n\nTo register new codes, augment [`SystemErrorMap`](#systemerrormap). They will be added to this union automatically.\n\n```ts\ntype SystemCode = Extract\u003ckeyof SystemErrorMap, string\u003e\n```\n\n### `SystemErrorMap`\n\nRegistry of system error codes (TypeScript interface).\n\nWhen developing utilities that use more codes, augment `SystemErrorMap` to register those codes:\n\n```ts\ndeclare module '@flex-development/errnode' {\n  interface SystemErrorMap {\n    ECUSTOM: true\n  }\n}\n```\n\n## Contribute\n\nSee [`CONTRIBUTING.md`](CONTRIBUTING.md).\n\nThis project has a [code of conduct](./CODE_OF_CONDUCT.md). By interacting with this repository, organization, or\ncommunity you agree to abide by its terms.\n\n[errors]: https://nodejs.org/api/errors.html\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[fn]: https://github.com/flex-development/tutils/blob/tutils%406.0.0-alpha.25/src/types/fn.ts\n\n[format]: https://github.com/hildjj/node-inspect-extracted\n\n[mlly]: https://github.com/flex-development/mlly\n\n[nodejs-error-codes]: https://nodejs.org/api/errors.html#nodejs-error-codes\n\n[ponyfill]: https://github.com/sindresorhus/ponyfill\n\n[syscall]: https://man7.org/linux/man-pages/man2/syscalls.2.html\n\n[typescript]: https://www.typescriptlang.org\n\n[yarn]: https://yarnpkg.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Ferrnode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflex-development%2Ferrnode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflex-development%2Ferrnode/lists"}