Skip to content
faultferry

Edition 0.1.1

Chart of safe passage for thrown errors

Surveyed for Node.js, Bun, Deno and browsers

Send errors across processes and bring them back whole.

faultferry turns any thrown value into plain JSON and rebuilds it on the other side: the same class, message, stack, cause chain, AggregateError members and custom properties. It works across workers, child processes, HTTP and message queues, and it never throws on hostile input.

  • 4.7 kBgzip, zero dependencies
  • 126tests, 100% line coverage
  • 1.7xfaster than serialize-error on every case measured

01Sailing directions

Send an error from one process to another in three steps

  1. Install the package on both sides.

    $ npm i faultferry
  2. Where the error is caught, serialize it before it crosses the boundary.

    import { serialize } from 'faultferry';
    
    try {
      await job();
    } catch (error) {
      channel.send(JSON.stringify(serialize(error)));
    }
  3. Where it arrives, deserialize it and throw or log it as the original error.

    import { deserialize } from 'faultferry';
    
    channel.on('message', (text) => {
      throw deserialize(JSON.parse(text));
    });

02Notice to mariners

Errors do not survive the trip

JSON.stringify(new Error('boom')) gives you an empty object. Workers, IPC and HTTP all move data, not errors, so the class, the cause and every custom field are lost on the way.

  1. JSON drops everything

    message and stack are not enumerable, so they vanish. Error classes, causes and AggregateError members vanish with them.

  2. structuredClone is not enough

    It keeps a cause, but custom classes come back as plain Error, AggregateError loses its errors and own properties like status or code are dropped.

  3. Hand rolled code breaks

    A cycle in a cause chain, a getter that throws or a revoked proxy turns a simple error logger into a crash in the code that was supposed to report the crash.

console.logJSON.stringify(error)
const cause = new RangeError('root');

JSON.stringify(new TypeError('boom', { cause }));
// '{}'

JSON.stringify(serialize(new TypeError('boom', { cause })));
// {"$error":"TypeError","name":"TypeError",
//  "message":"boom","stack":"...",
//  "cause":{"$error":"RangeError","name":"RangeError",
//    "message":"root","stack":"..."}}

03Logbook

Build an error, ferry it, inspect what lands

Everything here runs the real library in your browser. Shape an error, read the JSON that would cross the wire, then edit that JSON and watch deserialize rebuild it.

04Chart legend

Everything an error carries, nothing it cannot

Exact round trips
Prototype, name, message, stack and every own enumerable property come back, with the same enumerability as the original.
Cause chains with cycles
Cycles and shared references travel as $ref pointers and are rebuilt with the same identity, instead of becoming the string [Circular].
Every built in error
AggregateError.errors, SuppressedError.error and suppressed, and DOMException name and code, from this realm or another one.
Custom classes
register(HttpError) on both sides and instances come back as HttpError. Constructors are never called, so required arguments do not matter.
Any thrown value
Strings, objects, undefined, NaN, -0, BigInt, Date, RegExp, Map and Set all survive. Nothing is wrapped in a fake error.
Hostile input is fine
Getters that throw, revoked proxies, prototype traps, huge stacks and garbage JSON: serialize and deserialize never throw.
Limits you control
maxDepth, maxNodes, maxLength and maxItems keep payloads bounded. stack: false strips traces before errors reach a client.
isError that tells the truth
Uses the native Error.isError when present and a correct fallback otherwise, including errors from iframes and node:vm contexts.

05Routes

Drop it in where errors cross a boundary

06Pilot book

Five functions

serialize(value, options?)
Returns a JSON safe value. Options: maxDepth (32), maxNodes (10000), maxLength, maxItems, stack (true), toJSON (true), classes.
deserialize(data, options?)
Rebuilds errors with the right prototype. Unknown classes become Error with the original name. Options: maxDepth (256), classes.
register(ErrorClass, name?)
Registers a class under a wire name (default: the class name). Returns the class.
unregister(classOrName)
Removes a registered class by class or by name.
isError(value)
True for real error objects, cross realm safe.

07Tide table

How it compares

Measured on Node 24 with structuredClone and serialize-error 13.1.0. Each cell is what you get back after a round trip.

After a round tripfaultferryserialize-error 13.1.0structuredClone
Custom class instanceKeptNeeds addKnownErrorConstructorLost
AggregateError membersKeptKeptLost
SuppressedErrorKeptLostLost
DOMExceptionKeptPlain Error with name and codeKept
Circular causeKeptBecomes the string [Circular]Kept
Own properties (code, errno, status)KeptKeptLost
undefined, NaN, BigInt, Date valuesKeptDropped or turned into stringsKept
Thrown stringKeptWrapped in NonErrorKept
Getters that throwSkipped, never throwsThrows on an own property getterThrows on a message getter
JSON text outputKeptKeptLost
  • Key
  • kept
  • lost
  • partly kept

08Speed trials

Fast on both ends

Operations per second, median of five runs, higher is better. Node 24.16.0, AMD Ryzen 7 7800X3D 8-Core Processor, win32 x64, 2026-12-04.

serialize + JSON.stringify

  • faultferry
  • serialize-error
  • structuredClone (no JSON)
simple TypeError
faultferry1.65M
serialize-error893k
structuredClone (no JSON)697k
cause chain x6
faultferry319k
serialize-error160k
structuredClone (no JSON)193k
error with props
faultferry821k
serialize-error426k
structuredClone (no JSON)757k
AggregateError x20
faultferry68k
serialize-error40k
structuredClone (no JSON)638k

JSON.parse + deserialize

  • faultferry
  • serialize-error
simple TypeError
faultferry548k
serialize-error143k
cause chain x6
faultferry98k
serialize-error10k
error with props
faultferry313k
serialize-error121k
AggregateError x20
faultferry22k
serialize-error3k

structuredClone does not produce JSON and drops AggregateError members, which is why it is so fast on that case. Run npm run bench to measure on your machine.

09Draught

Small enough to forget about

One ESM file with a CommonJS build, typed with a hand written index.d.ts, tree shakeable and free of side effects.

4.7kB

gzip, comments and whitespace stripped

0

runtime dependencies

Runs where your errors run

  • Node.js 18 and newer
  • Bun
  • Deno
  • Modern browsers
  • Web Workers and Service Workers
  • ESM, CommonJS, TypeScript

10Harbor master

Questions

Ship your next error across the river.

One install, five functions, zero dependencies. Errors leave with their class, cause and fields, and arrive with all of them.

Open the playground
$ npm i faultferry