
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
error-class
Advanced tools
This module provides typed errors that closely emulate the native Error
class to a pedantic degree.
$ npm install error-class
The default export is a function that accepts only one argument, the name of the typed error.
var errorClass = require('error-class')
var SpecialError = errorClass('SpecialError')
var instance = new SpecialError('foobar')
instance.message // 'foobar'
import errorClass from 'error-class'
const HumanError = errorClass('HumanError')
const hungryError = new HumanError(`I'm hungry!`)
hungryError.name // 'HumanError'
hungryError.message // `I'm hungry!`
hungryError.stack // Platform-specific error stack trace.
hungryError.hasOwnProperty('name') // false (!)
hungryError.hasOwnProperty('message') // true
hungryError.hasOwnProperty('stack') // true
// Just like native errors, it doesn't require using `new`.
const thirstyError = HumanError(`I'm thirsty!`)
Object.keys(thirstyError).length === 0 // True, all properties are non-enumerable.
Object.keys(Object.getPrototypeOf(instance)).length === 0 // Prototype non-enumerable.
thirstyError.constructor === HumanError // True.
thirstyError.constructor.name === 'HumanError' // True.
thirstyError instanceof Error // True, errors inherit from native `Error` class.
thirstyError instanceof HumanError // Also true, of course.
This software is licensed under the MIT License.
FAQs
Typed errors that closely emulate the native Error class.
The npm package error-class receives a total of 999 weekly downloads. As such, error-class popularity was classified as not popular.
We found that error-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.