Priority
P3
Area
Feature enhancement: richer built-in type fidelity
Problem
The built-in Error handler preserves name, message, and cause, but drops other useful diagnostic state such as stack and enumerable custom fields.
Example fields that are currently lost:
const err = new Error("failed");
err.stack; // present in most runtimes
(err as Error & { code?: string }).code = "E_TEST";
const result = decode<{ err: Error }>(encode({ err })).err;
result.stack; // new local stack or undefined, not the original stack
(result as Error & { code?: string }).code; // undefined
Relevant code:
src/types.ts: serializeErrorDetails() only emits name, message, and optional cause.
src/types.ts: deserializeErrorDetails() reconstructs a plain Error and assigns name.
Expected behavior
Consider an opt-in or backwards-compatible enhancement that preserves more diagnostic details for callers who use Error values as transportable diagnostics.
Suggested approach
Keep the existing structured marker for compatibility, and add optional fields such as stack and a JSON-safe record of enumerable own properties. Avoid executing constructors for arbitrary error names.
Acceptance criteria
- Add tests for preserving
stack when present.
- Add tests for JSON-compatible enumerable custom fields such as
code or status.
- Existing legacy Error message strings and current structured Error payloads still decode correctly.
- Document which Error fields are preserved and which are intentionally excluded.
Priority
P3
Area
Feature enhancement: richer built-in type fidelity
Problem
The built-in
Errorhandler preservesname,message, andcause, but drops other useful diagnostic state such asstackand enumerable custom fields.Example fields that are currently lost:
Relevant code:
src/types.ts:serializeErrorDetails()only emitsname,message, and optionalcause.src/types.ts:deserializeErrorDetails()reconstructs a plainErrorand assignsname.Expected behavior
Consider an opt-in or backwards-compatible enhancement that preserves more diagnostic details for callers who use
Errorvalues as transportable diagnostics.Suggested approach
Keep the existing structured marker for compatibility, and add optional fields such as
stackand a JSON-safe record of enumerable own properties. Avoid executing constructors for arbitrary error names.Acceptance criteria
stackwhen present.codeorstatus.