Written by

Nesalia Inc

Published

Fri Jun 05 2026

Getting Started with @deessejs/errors

Learn how to implement Python-inspired error handling in TypeScript with exception chaining, hierarchical inheritance, and rich error semantics.

Introduction

@deessejs/errors brings Python's powerful error handling system to TypeScript. If you've ever wished JavaScript had the same expressive error handling as Python, this library is for you.

Installation

npm install @deessejs/errors

Creating Your First Error

Unlike traditional JavaScript errors that use classes, @deessejs/errors uses a function-based API:

import { error } from '@deessejs/errors';

// Create an error factory
const ValidationError = error({
  name: 'ValidationError',
  message: 'Validation failed for field "{field}"',
});

// Use it
const err = ValidationError({ field: 'email' });
console.log(err.message); // "Validation failed for field "email""

Exception Chaining

The .from() method lets you chain errors together, preserving the full context of what went wrong:

import { error, raise } from '@deessejs/errors';

const AppError = error({ name: 'AppError' });
const ValidationError = error({ name: 'ValidationError' });

try {
  // Something fails
  raise(ValidationError({ field: 'email' }));
} catch (e) {
  // Chain the error
  AppError({}).from(e);
}

Hierarchical Inheritance

Build error hierarchies that let you catch errors at different levels:

import { error, is } from '@deessejs/errors';

const AppError = error({ name: 'AppError' });
const ValidationError = error({
  name: 'ValidationError',
  inherits: AppError,
});

// Now you can catch any AppError
if (is(err, AppError)) {
  // Handles both ValidationError and AppError
}

Next Steps

Happy error handling!