Error Handling,
Reimagined.
A TypeScript library that brings Python-inspired error handling to JavaScript. Exception chaining, hierarchical inheritance, and rich error semantics through a function-based API.
import { error, raise, is, causes } from '@deessejs/errors';
const ValidationError = error({
name: 'ValidationError',
message: 'Field "{field}" is invalid: {reason}',
});
const err = ValidationError({
field: 'email',
reason: 'invalid format',
});
// Chain errors with .from()
appErr.from(err);
// Type-safe checking
if (is(err, ValidationError)) {
console.log(err.fields.field); // "email"
}Features
Everything you need for robust error handling in TypeScript.
Exception Chaining
Preserve the full context of errors with the .from() method. Traverse the complete error chain to understand what went wrong.
Hierarchical Inheritance
Organize errors in meaningful hierarchies that reflect your domain. Use inheritance to categorize and handle errors by type.
Message Templates
Define errors with {placeholder} templates that are replaced at runtime. Rich, contextual error messages made easy.
TypeScript Native
Full type safety with generic error factories. Leverage TypeScript to catch errors before they happen.
Type Guards
The is() function provides type-safe error checking.
Schema Validation
Validate error fields with Standard Schema (Zod, Valibot, etc.).
Cause Traversal
Use causes() to iterate the full error chain.
Explore the docs
Learn how to build robust error handling in your TypeScript projects.
Read the docs →From fragile to robust.
Stop relying on fragile string matching. Get type-safe, structured errors that make debugging a breeze.
// Traditional approach
throw new Error('Validation failed');
catch (err) {
if (err.message.includes('Validation')) {
// String matching... fragile!
}
}// @deessejs/errors approach
raise(ValidationError({ field: 'email' }));
catch (err) {
if (is(err, ValidationError)) {
// Type-safe, reliable
console.log(err.fields.field);
}
}