Gathering detailed insights and metrics for error-class-utils
Gathering detailed insights and metrics for error-class-utils
Gathering detailed insights and metrics for error-class-utils
Gathering detailed insights and metrics for error-class-utils
@lskjs/err
LSK.js – err – Error class and utils for custom code and message extracting
@lsk4/err
LSK.js – err – Error class and utils for custom code and message extracting 123
error-utils
- make error class - chain errors - convert error to object - convert object to error
@vl-utils/e-error
Extended Error class with objects support
npm install error-class-utils
Typescript
Module System
Min. Node Version
Node Version
NPM Version
81
Supply Chain
100
Quality
76.8
Maintenance
100
Vulnerability
100
License
JavaScript (92.81%)
TypeScript (7.19%)
Total Downloads
669,371
Last Day
48
Last Week
5,834
Last Month
21,661
Last Year
374,108
MIT License
3 Stars
399 Commits
2 Watchers
1 Branches
1 Contributors
Updated on May 25, 2025
Minified
Minified + Gzipped
Latest Version
4.0.1
Package Id
error-class-utils@4.0.1
Unpacked Size
17.68 kB
Size
5.74 kB
File Count
11
NPM Version
10.9.2
Node Version
23.10.0
Published on
Mar 29, 2025
Cumulative downloads
Total Downloads
Last Day
-44.2%
48
Compared to previous day
Last Week
20.4%
5,834
Compared to previous week
Last Month
-6.2%
21,661
Compared to previous month
Last Year
55.6%
374,108
Compared to previous year
Properly create error classes.
Useful utilities when creating custom error classes.
error.cause
on
older Node.js and browserserror.name
Error
has been
polyfilled1import { 2 ensureCorrectClass, 3 ponyfillCause, 4 setErrorName, 5} from 'error-class-utils' 6 7export class CustomError extends Error { 8 constructor(message, parameters) { 9 super(message, parameters) 10 11 // Fix some issues when `Error` has been polyfilled 12 ensureCorrectClass(this, new.target) 13 14 // Ponyfill `error.cause` on old Node.js/browsers 15 ponyfillCause(this, parameters) 16 } 17} 18 19// Properly set `error.name` as a non-enumerable and inherited property 20setErrorName(CustomError, 'CustomError')
1import { CustomError } from './errors.js' 2 3const cause = new Error('innerMessage') 4const error = new CustomError('message', { cause }) 5console.log(error instanceof CustomError) // true 6console.log(error.name) // 'CustomError' 7console.log(error.cause) // Error: innerMessage ...
1npm install error-class-utils
This package works in both Node.js >=18.18.0 and browsers.
This is an ES module. It must be loaded using
an import
or import()
statement,
not require()
. If TypeScript is used, it must be configured to
output ES modules,
not CommonJS.
error
Error
new.target
typeof Error
Return value: void
Some Error
polyfills (such as
es-shims/error-cause
) prevent
extending from it. This fixes it.
The second argument must be
new.target
.
This must be called directly inside a class constructor, after
super(message, parameters)
.
1import { ensureCorrectClass } from 'error-class-utils' 2 3class CustomError extends Error { 4 constructor(message, parameters) { 5 super(message, parameters) 6 ensureCorrectClass(this, new.target) 7 } 8} 9 10// Thanks to `ensureCorrectClass()`, this is now always true even when 11// `Error` has been polyfilled 12console.log(new CustomError('message') instanceof CustomError) // true
error
Error
parameters
ErrorParams?
Return value: void
Ponyfills
error.cause
on
older Node.js and browsers.
This must be called inside a class constructor, after
super(message, parameters)
.
1import { ponyfillCause } from 'error-class-utils' 2 3class CustomError extends Error { 4 constructor(message, parameters) { 5 super(message, parameters) 6 ponyfillCause(this, parameters) 7 } 8} 9 10try { 11 throw new Error('innerMessage') 12} catch (cause) { 13 // Works on any platforms thanks to ponyfill 14 const error = new CustomError('message', { cause }) 15 console.log(error.cause.message) // 'innerMessage' 16}
ErrorClass
typeof Error
name
string
Return value: void
Set an ErrorClass
's
name
.
This must be performed on an error class, not instance. Unlike setting
this.name = '...'
inside an error's constructor, this follows the native
Error
classes' pattern where error.name
:
Error
suffixname
1import { setErrorName } from 'error-class-utils' 2 3class CustomError extends Error {} 4setErrorName(CustomError, 'CustomError') 5 6console.log(CustomError.name) // 'CustomError' 7console.log(CustomError.prototype.name) // 'CustomError' 8 9const error = new CustomError('message') 10console.log(error.name) // 'CustomError' 11console.log(Object.keys(error).includes('name')) // false
modern-errors
: Handle errors in
a simple, stable, consistent wayerror-custom-class
: Create
one error classerror-serializer
: Convert
errors to/from plain objectsnormalize-exception
:
Normalize exceptions/errorsis-error-instance
: Check if
a value is an Error
instancemerge-error-cause
: Merge an
error with its cause
set-error-class
: Properly
update an error's classset-error-message
: Properly
update an error's messagewrap-error-message
:
Properly wrap an error's messageset-error-props
: Properly
update an error's propertiesset-error-stack
: Properly
update an error's stackerror-cause-polyfill
:
Polyfill error.cause
handle-cli-error
: 💣 Error
handler for CLI applications 💥log-process-errors
: Show
some ❤ to Node.js process errorserror-http-response
:
Create HTTP error responseswinston-error-format
: Log
errors with WinstonFor any question, don't hesitate to submit an issue on GitHub.
Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.
This project was made with ❤️. The simplest way to give back is by starring and sharing it online.
If the documentation is unclear or has a typo, please click on the page's Edit
button (pencil icon) and suggest a correction.
If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!
No vulnerabilities found.
No security vulnerabilities found.