Changelog - 2026-11-08
ApplicationError.fromUnknown wraps a caught value
New FeatureIn one line. A catch block can turn whatever it caught into an ApplicationError with one call, without a hand-written wrapper.
typescript
import { ApplicationError } from '@venizia/ignis-helpers';
try {
await someOperation();
} catch (error) {
throw ApplicationError.fromUnknown({ error });
}What changed
ApplicationError.fromUnknown({ error })takes any value and returns anApplicationError. It never throws:undefined,null, a string, a symbol, a Proxy, an object with throwing getters, a frozen object and a circular structure all work.- An
ApplicationErrorcomes back as the same instance, including one built by another installed copy of the package. - Anything else becomes a new error, with the original kept as
cause. What a client sees depends on the value. A value with a valid HTTP status (an integerstatusCodefrom 400 to 599, or astatusfrom 400 to 499) keeps that status and its stringmessage. Any other value becomes a500that the error middleware answers as an unexpected error:Internal Server Errorin production, with the real message (one line, control characters escaped), thecauseand the stack in the log only. A driver or engine error carries SQL, paths and hosts, so wrapping it never puts them in a response.
Who is affected
- Code that wraps a caught value itself. You can replace your wrapper with this call. No action needed otherwise.
- Everyone else. No action needed.
Details
- The wrapped error is marked unexpected by a private symbol (not a public flag), which the error middleware reads. It does not enumerate, so it never reaches JSON,
extraor a response. - The message you keep is the message a client reads in production, but only for a value that carried a valid status. The error middleware replaces only an unexpected error's message with
Internal Server Error; anApplicationErrormessage goes out as written. Wrap a value whose message is safe to show, or usegetErrorwith a message you chose. Thecauseis not sent in production. - See Wrap a caught value of any type.