Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@flex-development/errnode
Advanced tools
Universal API for creating Node.js errors
ERR_AMBIGUOUS_ARGUMENT(reason)
ERR_ARG_NOT_ITERABLE(name)
ERR_ASYNC_CALLBACK(name)
ERR_ILLEGAL_CONSTRUCTOR()
ERR_IMPORT_ASSERTION_TYPE_FAILED(id, type)
ERR_IMPORT_ASSERTION_TYPE_MISSING(id, type)
ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED(type)
ERR_INCOMPATIBLE_OPTION_PAIR(option1, option2)
ERR_INVALID_ARG_TYPE(name, expected, actual)
ERR_INVALID_ARG_VALUE(name, value[, reason])
ERR_INVALID_MODULE_SPECIFIER(request[, reason][, base])
ERR_INVALID_PACKAGE_CONFIG(id[, base][, reason])
ERR_INVALID_PACKAGE_TARGET(dir, key, target[, internal][, base])
ERR_INVALID_RETURN_VALUE(expected, name, value)
ERR_INVALID_URL(input)
ERR_METHOD_NOT_IMPLEMENTED(method)
ERR_MISSING_OPTION(option)
ERR_MODULE_NOT_FOUND(id, base[, type])
ERR_NETWORK_IMPORT_DISALLOWED(specifier, base, reason)
ERR_OPERATION_FAILED(reason)
ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, base[, dir])
ERR_PACKAGE_PATH_NOT_EXPORTED(dir, subpath[, base])
ERR_UNHANDLED_ERROR([err])
ERR_UNKNOWN_BUILTIN_MODULE(name)
ERR_UNKNOWN_ENCODING(encoding)
ERR_UNKNOWN_FILE_EXTENSION(ext, id[, suggestion])
ERR_UNKNOWN_MODULE_FORMAT(format, id)
ERR_UNSUPPORTED_DIR_IMPORT(id, base)
ERR_UNSUPPORTED_ESM_URL_SCHEME(url, supported[, windows])
This package provides a universal API for creating Node.js errors.
This package is designed to help developers build Node.js tools like ponyfills, as well as more verbose tools like
mlly
, by providing a set of utilities and constructor functions for creating Node.js errors.
Error.stackTraceLimit
to
capture larger stack traces. This is not implemented to maintain browser compatibility.This package is ESM only.
yarn add @flex-development/errnode
From Git:
yarn add @flex-development/errnode@flex-development/errnode
See Git - Protocols | Yarn for details on requesting a specific branch, commit, or tag.
import {
createNodeError,
ErrorCode,
type MessageFn,
type NodeError,
type NodeErrorConstructor
} from '@flex-development/errnode'
/**
* [`ERR_INVALID_URL`][1] schema.
*
* [1]: https://nodejs.org/api/errors.html#err_invalid_url
*
* @extends {NodeError<TypeError>}
*/
interface ErrInvalidUrl extends NodeError<TypeError> {
/**
* Error code.
*/
code: ErrorCode.ERR_INVALID_URL
/**
* URL that failed to parse.
*
* @example
* 'http://[127.0.0.1\x00c8763]:8000/'
*/
input: string
}
/**
* `ERR_INVALID_URL` model.
*
* Thrown when an invalid URL is passed to a [WHATWG][1] [`URL` constructor][2]
* or [`url.parse()`][3] to be parsed.
*
* [1]: https://nodejs.org/api/url.html#the-whatwg-url-api
* [2]: https://nodejs.org/api/url.html#new-urlinput-base
* [3]: https://nodejs.org/api/url.html#urlparseurlstring-parsequerystring-slashesdenotehost
*
* @see https://nodejs.org/api/errors.html#err_invalid_url
*
* @class
*
* @param {string} input - URL that failed to parse
* @return {ErrInvalidUrl} `TypeError` instance
*/
const ERR_INVALID_URL: NodeErrorConstructor<
TypeErrorConstructor,
MessageFn<[string]>,
ErrInvalidUrl
> = createNodeError(
ErrorCode.ERR_INVALID_URL,
TypeError,
/**
* Creates an [`ERR_INVALID_URL`][1] message.
*
* [1]: https://nodejs.org/api/errors.html#err_invalid_url
*
* @see https://github.com/nodejs/node/blob/v19.3.0/lib/internal/errors.js#L1381-L1386
*
* @this {ErrInvalidUrl}
*
* @param {string} input - URL that failed to parse
* @return {string} Error message
*/
function msg(this: ErrInvalidUrl, input: string): string {
this.input = input
return 'Invalid URL'
}
)
/**
* URL that will fail to parse.
*
* @const {string} BAD_URL
*/
const BAD_URL: string = 'http://[127.0.0.1\x00c8763]:8000/'
/**
* {@linkcode ERR_INVALID_URL} instance.
*
* @const {ErrInvalidUrl} err
*/
const err: ErrInvalidUrl = new ERR_INVALID_URL(BAD_URL)
console.error(err)
console.debug('err instanceof TypeError:', err instanceof TypeError)
...running that yields:
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (file:////home/runner/work/errnode/errnode/src/create-node-error.ts:103:5)
at file:////home/runner/work/errnode/errnode/scratch.ts:90:28
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12) {
code: 'ERR_INVALID_URL',
input: 'http://[127.0.0.1\x00c8763]:8000/'
}
err instanceof TypeError: true
This package exports the following identifiers:
ERR_AMBIGUOUS_ARGUMENT
ERR_ARG_NOT_ITERABLE
ERR_ASYNC_CALLBACK
ERR_ILLEGAL_CONSTRUCTOR
ERR_IMPORT_ASSERTION_TYPE_FAILED
ERR_IMPORT_ASSERTION_TYPE_MISSING
ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED
ERR_INCOMPATIBLE_OPTION_PAIR
ERR_INVALID_ARG_TYPE
ERR_INVALID_ARG_VALUE
ERR_INVALID_MODULE_SPECIFIER
ERR_INVALID_PACKAGE_CONFIG
ERR_INVALID_PACKAGE_TARGET
ERR_INVALID_RETURN_VALUE
ERR_INVALID_URL
ERR_METHOD_NOT_IMPLEMENTED
ERR_MISSING_OPTION
ERR_MODULE_NOT_FOUND
ERR_NETWORK_IMPORT_DISALLOWED
ERR_OPERATION_FAILED
ERR_PACKAGE_IMPORT_NOT_DEFINED
ERR_PACKAGE_PATH_NOT_EXPORTED
ERR_UNHANDLED_ERROR
ERR_UNKNOWN_BUILTIN_MODULE
ERR_UNKNOWN_ENCODING
ERR_UNKNOWN_FILE_EXTENSION
ERR_UNKNOWN_MODULE_FORMAT
ERR_UNSUPPORTED_DIR_IMPORT
ERR_UNSUPPORTED_ESM_URL_SCHEME
createNodeError
determineSpecificType
errors
There is no default export.
Constructor functions representing Node.js error codes, callable with and without the new
keyword. Constructor
arguments are used to generate error messages.
Models can be imported individually:
import {
ERR_INVALID_ARG_VALUE,
ERR_INVALID_MODULE_SPECIFIER,
ERR_INVALID_PACKAGE_CONFIG,
ERR_INVALID_PACKAGE_TARGET,
ERR_INVALID_URL,
ERR_MODULE_NOT_FOUND,
ERR_NETWORK_IMPORT_DISALLOWED,
ERR_PACKAGE_IMPORT_NOT_DEFINED,
ERR_PACKAGE_PATH_NOT_EXPORTED,
ERR_UNKNOWN_FILE_EXTENSION,
ERR_UNSUPPORTED_DIR_IMPORT,
ERR_UNSUPPORTED_ESM_URL_SCHEME
} from '@flex-development/errnode'
...or all at once using the errors
export:
import { errors } from '@flex-development/errnode'
Note: This package does not export a model for every error code. Submit a feature request (or pull request if
you're up for the challenge :wink:) to add a model. For more fine-grained control, however, use
createNodeError
instead.
ERR_AMBIGUOUS_ARGUMENT(name, reason)
Thrown when a function argument is being used in a way that suggests that the function signature may be misunderstood.
{string}
name
— Name of ambiguous argument{string}
reason
— Reason name
is ambiguous{NodeError<TypeError>}
ERR_ARG_NOT_ITERABLE(name)
Thrown when an iterable argument (i.e. a value that works with for...of
loops) is required, but not provided to a
Node.js API.
{string}
name
— Name of non-iterable argument{NodeError<TypeError>}
ERR_ASYNC_CALLBACK(name)
Thrown when an attempt is made to register something that is not a function as an AsyncHooks
callback.
{string}
name
— Name of argument that must be a function{NodeError<TypeError>}
Source:
src/models/err-async-callback.ts
ERR_ILLEGAL_CONSTRUCTOR()
Thrown when an attempt is made to construct an object using a non-public constructor.
{NodeError<TypeError>}
ERR_IMPORT_ASSERTION_TYPE_FAILED(id, type)
Thrown when an import assertion has failed, preventing the specified module from being imported.
{string}
id
— Id of module that cannot be imported{string}
type
— Invalid import assertion type{NodeError<TypeError>}
ERR_IMPORT_ASSERTION_TYPE_MISSING(id, type)
Thrown when an import assertion is missing, preventing the specified module from being imported.
{string}
id
— Id of module that cannot be imported{string}
type
— Invalid import assertion type{NodeError<TypeError>}
ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED(type)
Thrown when an import assertion is not supported by a version of Node.js.
{string}
type
— Unsupported import assertion type{NodeError<TypeError>}
ERR_INCOMPATIBLE_OPTION_PAIR(option1, option2)
Thrown when an option pair is incompatible with each other and cannot be used at the same time.
{string}
option1
— Option that cannot be used{string}
option2
— Option that is incompatible with option1
{NodeError<TypeError>}
ERR_INVALID_ARG_TYPE(name, expected, actual)
Thrown when an argument of the wrong type is passed to a Node.js API.
{string}
name
— Name of invalid argument or property{OneOrMany<string>}
expected
— Expected type(s){unknown}
actual
— Value supplied by user{NodeError<TypeError>}
ERR_INVALID_ARG_VALUE(name, value[, reason])
Thrown when an invalid or unsupported value is passed for a given argument or property.
{string}
name
— Name of invalid argument or property{unknown}
value
— Value supplied by user{string?}
[reason='is invalid']
— Reason value
is invalid{NodeError<TypeError>}
ERR_INVALID_MODULE_SPECIFIER(request[, reason][, base])
Thrown when an imported module string is an invalid URL, package name, or package subpath specifier.
{string}
request
— Invalid module specifier{string?}
[reason='']
— Reason request
is invalid{string?}
[base='']
— Id of module request
was imported from{NodeError<TypeError>}
ERR_INVALID_PACKAGE_CONFIG(id[, base][, reason])
Thrown when a package.json
file fails parsing.
{string}
id
— Location of invalid package.json
file{string?}
[base='']
— Id of module being imported. May also include where module is being imported from{string?}
[reason='']
— Reason package config is invalid{NodeError}
ERR_INVALID_PACKAGE_TARGET(dir, key, target[, internal][, base])
Thrown when a package.json
"exports"
or "imports"
field contains an invalid target mapping value for
the attempted module resolution.
{string}
dir
— Id of directory containing package.json
{string}
key
— "exports"
or "imports"
key{unknown}
target
— Invalid package target{boolean?}
[internal=false]
— target
is "imports"
?{string?}
[base='']
— Id of module package.json
was imported from{NodeError}
ERR_INVALID_RETURN_VALUE(expected, name, value)
Thrown when a function does not return an expected value type on execution, such as when a function is expected to return a promise.
{string}
expected
— Expected return value type{string}
name
— Name of function that returned invalid value type{unknown}
value
— Value supplied by user{NodeError<TypeError>}
ERR_INVALID_URL(input)
Thrown when an invalid URL is passed to a WHATWG URL
constructor or url.parse()
to be parsed.
{string}
input
— URL that failed to parse{ErrInvalidUrl}
Source:
src/models/err-invalid-url.ts
ERR_METHOD_NOT_IMPLEMENTED(method)
Thrown when a method is required but not implemented.
{string}
method
— Method name{NodeError}
ERR_MISSING_OPTION(option)
Thrown when a required option is missing. For APIs that accept options objects, some options might be mandatory.
{string}
option
— Option name{NodeError<TypeError>}
Source:
src/models/err-missing-option.ts
ERR_MODULE_NOT_FOUND(id, base[, type])
Thrown when a module file cannot be resolved by the ECMAScript modules loader while attempting an import
operation or
when loading a program entry point.
{string}
id
— Id of missing module{string}
base
— Id of module id
was imported from{string?}
[type='package']
— Module file type{NodeError}
ERR_NETWORK_IMPORT_DISALLOWED(specifier, base, reason)
Thrown when a network module attempts to load another module that it is not allowed to load.
{string}
specifier
— Invalid module specifier{string}
base
— Id of module specifier
was imported from{string}
reason
— Reason for error{NodeError}
ERR_OPERATION_FAILED(reason)
Thrown when an operation has failed. Typically used to signal the general failure of an asynchronous operation.
{string}
reason
— Reason for operation failure{NodeError}
ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, base[, dir])
Thrown when a package.json
"imports"
field does not define the given package import specifier.
{string}
specifier
— Invalid package import specifier{string}
base
— Id of module specifier
was imported from{string?}
[dir='']
— Id of directory containing package.json
{NodeError<TypeError>}
ERR_PACKAGE_PATH_NOT_EXPORTED(dir, subpath[, base])
Thrown when a package.json
"exports"
field does not export the requested subpath.
{string}
dir
— Id of directory containing package.json
{string}
subpath
— Requested subpath{string?}
[base='']
— Id of module subpath
was imported from{NodeError}
ERR_UNHANDLED_ERROR([err])
Thrown when an unhandled error occurs.
{string?}
[err='']
— Stringified error{NodeError}
ERR_UNKNOWN_BUILTIN_MODULE(name)
Thrown when an unknown builtin module is encountered.
{string}
name
— Module name{NodeError}
ERR_UNKNOWN_ENCODING(encoding)
Thrown when an invalid or unknown encoding option is passed to a Node.js API.
{string}
encoding
— Invalid or unknown encoding{NodeError<TypeError>}
ERR_UNKNOWN_FILE_EXTENSION(ext, id[, suggestion])
Thrown when an attempt is made to load a module with an unknown or unsupported file extension.
{string}
ext
— Unknown or unsupported file extension{string}
id
— Id of module containing ext
{string?}
[suggestion='']
— Recommended fix{NodeError<TypeError>}
ERR_UNKNOWN_MODULE_FORMAT(format, id)
Thrown when an attempt is made to load a module with an unknown or unsupported format.
{string}
format
— Unknown or unsupported format{string}
id
— Id of module with format
{NodeError<RangeError>}
ERR_UNSUPPORTED_DIR_IMPORT(id, base)
Thrown when a directory URL is import
ed.
{string}
id
— Module id of directory{string}
base
— Id of module id
was imported from{NodeError}
ERR_UNSUPPORTED_ESM_URL_SCHEME(url, supported[, windows])
Thrown when an unsupported URL scheme is used in an import
statement. URL schemes other than file
and data
are unsupported.
{URL}
url
— URL containing unsupported scheme{string[]}
supported
— Supported URL schemes{boolean?}
[windows=false]
— Windows operating system?{NodeError}
createNodeError(code, Base, message)
Creates a Node.js error constructor.
If the given error message
is a function, constructor arguments are passed to message
. If the message
is a string,
constructor arguments are passed to util.format
instead.
{ErrorCode}
code
— Node.js error code{B extends ErrorConstructor}
Base
— Error base class{M extends any[] | MessageFn | string}
message
— Error message or message function{NodeErrorConstructor<B, M>}
NodeError
constructorSource:
src/create-node-error.ts
determineSpecificType(value)
Determines the specific type of a value for type-mismatch errors.
{unknown}
value
— Value to evaluate{string}
Specific type of value
Source:
src/determine-specific-type.ts
This package is fully typed with TypeScript. It exports the following definitions:
See CONTRIBUTING.md
.
1.5.0 (2023-02-03)
b8f27f5
] deps-dev: bump @flex-development/mlly from 1.0.0-alpha.7 to 1.0.0-alpha.97cb02b0
] deps-dev: bump typescript from 5.0.0-dev.20221215 to 5.0.0-dev.202301284107ef9
] deps-dev: cleanup changelog depse00da7f
] deps: bump @flex-development/tutils from 6.0.0-alpha.9 to 6.0.0-alpha.10d28f76c
] nvm: bump node from 16 to 194d1eb64
] deps: bump actions/cache from 3.2.2 to 3.2.3ebce7da
] deps: Bump actions/github-script from 6.3.3 to 6.4.0 (#39)464efa8
] deps: bump actions/setup-node from 3.5.1 to 3.6.0de257af
] deps: bump actions/upload-artifact from 3.1.1 to 3.1.28e43151
] deps: Bump dependabot/fetch-metadata from 1.3.5 to 1.3.6 (#37)f13faa4
] workflows: [approve-pr
] refactor approval step conditional49edebc
] workflows: [ci
] jobs.setup
-> jobs.metadata
3079ae4
] workflows: [ci
] add version
output to metadata
job8f3d76b
] workflows: [ci
] make typescript matrix dynamicc1dc67b
] workflows: [ci
] refactor metadata
job conditional46130b7
] workflows: [ci
] skip workflow run for @dependabot on push
b6aab62
] workflows: [ci
] skip workflow run for @flexdevelopment on push
c64ee0f
] workflows: [integrity
] update pull_request
event activity typesbd26e5d
] workflows: [typescript-canary
] add tsconfig.json
prep step288c689
] models: ERR_INVALID_RETURN_VALUE
48af1d1
] [eslint] update rules for test files0bc284e
] update project architecturec7b9e91
] github: add "typescript version" input to bug report template7fac1a8
] github: add commit scope nvm
68fb47c
] github: add commit scope spelling
aaf8e26
] github: cleanup reference link in .github/funding.yml
01eeb03
] github: remove "tests" section from pull request templatee749983
] github: remove git@bitbucket.org
alias from sample .gitconfig
553a21c
] yarn: disable transparent workspaces0dfde52
] replace deprecated faker
methodsFAQs
Universal API for creating Node.js errors
We found that @flex-development/errnode demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.