modern-errors
modern-errors is a lightweight JavaScript library for creating and handling custom error classes with consistent patterns across Node.js and browsers. It provides utilities to wrap errors, normalize invalid errors, aggregate errors, and extend functionality via plugins.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | ehmicky/modern-errors |
| Owner | ehmicky |
| Primary language | JavaScript |
| License | MIT — OSI-approved |
| Stars | 1.5k |
| Forks | 20 |
| Open issues | 2 |
| Latest release | 7.1.4 (2025-10-09) |
| Last updated | 2026-06-23 |
| Source | https://github.com/ehmicky/modern-errors |
What modern-errors is
ES module library offering error class factories via `.subclass()`, error property management (enumerable and non-enumerable), error cause wrapping with automatic message merging, normalization of non-Error types, and a plugin architecture for serialization, HTTP responses, logging, and stack trace manipulation.
Get the modern-errors source
Clone the repository and explore it locally.
git clone https://github.com/ehmicky/modern-errors.gitcd modern-errors# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Plan your error class hierarchy upfront (BaseError → domain-specific subclasses) to avoid fragmentation and enable consistent `instanceof` checks across modules.
- Decide on property naming convention for internal/secret properties (prefix with `_` to make non-enumerable) to prevent accidental logging or serialization of sensitive data.
- Test error normalization behavior in your catch blocks, especially if third-party libraries throw non-Error objects (strings, objects) that need conversion.
- Evaluate which plugins are needed (serialize, winston, http, etc.) early; add them only if they solve a real requirement to keep bundle size minimal.
- Ensure all error classes are exported and documented so downstream code and consumers can rely on `instanceof` checks and error recovery strategies.
When to avoid it — and what to weigh
- Already using a mature error framework — If your project heavily depends on a framework with built-in error handling (e.g., Express error middleware, NestJS exception filters), adding modern-errors may introduce redundant abstraction unless you need cross-platform consistency.
- Minimal error handling needs — For simple scripts or prototypes with few error types, the overhead of defining error classes and subclasses may outweigh the benefit. Standard Error or lightweight custom classes may suffice.
- Strong legacy CommonJS codebase — modern-errors is ES-module-only and requires Node.js >=18.18.0 with ESM output. Migrating a large CommonJS project solely to use this library is likely not cost-effective.
- Incompatible plugin ecosystem — If none of the available plugins match your logging, monitoring, or serialization stack, you would need to author custom plugins, which may negate the convenience benefit.
License & commercial use
MIT License. Permissive OSI-approved license allowing commercial use, modification, and distribution with no restrictions beyond attributing the original creator.
MIT License clearly permits commercial use without restrictions. However, verify that plugins used (if separate npm packages) also have compatible licenses. The library itself imposes no constraints on commercial applications.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Good |
| Assessment confidence | High |
Library itself does not perform encryption, authentication, or network operations—it is a data structuring tool. Primary concerns: (1) Internal error properties (prefixed `_`) are not enumerable but still accessible; ensure no secrets are stored as error properties. (2) Error messages and stacks may leak file paths or code details if serialized and exposed; use modern-errors-serialize with caution in public APIs. (3) Plugin ecosystem—vet plugins for injection vulnerabilities or unsafe serialization.
Alternatives to consider
Verror (Node.js only, older maintenance)
Lightweight error wrapping with cause chains, but smaller plugin ecosystem, slower maintenance, and no browser support compared to modern-errors.
HTTP status code + custom error classes (custom implementation)
Manual error hierarchy avoids a dependency but requires more boilerplate, testing, and lacks battle-tested patterns like error normalization and property merging.
Express/NestJS/Fastify built-in error handling
Framework-specific error handling is familiar to users but less portable across Node.js/browser boundaries and often cannot be easily reused in non-HTTP contexts.
Build on modern-errors with DEV.co software developers
If your team manages multiple error types across Node.js and browser environments, modern-errors can streamline error classification and reporting. Our engineers can help you design an error hierarchy and integrate monitoring plugins.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
modern-errors FAQ
Does modern-errors replace my logging library?
Can I use modern-errors in browsers?
What happens if I throw a non-Error object?
How do I avoid exposing sensitive data in error objects?
Software developers & web developers for hire
DEV.co helps companies turn open-source tools like modern-errors into production software. Our software development services cover the full lifecycle — architecture, web development, integration, and maintenance — delivered by software developers and web developers who ship. Engage our software development agency to implement or customize it for your open-source observability stack.
Ready to Improve Your Error Handling?
If your team manages multiple error types across Node.js and browser environments, modern-errors can streamline error classification and reporting. Our engineers can help you design an error hierarchy and integrate monitoring plugins.