v0.31.0
Minor Changes
-
69bf59e: Breaking:
createTaggedErrornow requires.withMessage(fn)as a mandatory terminal builder step before factories are available.What Changed
.withMessage(fn)is now required: Factories (XxxError,XxxErr) are only returned after calling.withMessage(). Previously you could destructure factories after just.withContext()or.withCause().- Message is auto-computed: The
messagefield is no longer a required input at the factory call site — it is derived from the template function passed to.withMessage(). You can still passmessage:as an optional override. - Context type tightened:
contextconstraint changed fromRecord<string, unknown>toJsonObject(values must be JSON-serializable). - Strict builder/factory separation:
ErrorBuilderonly has chain methods (.withContext(),.withCause(),.withMessage()).FinalFactoriesonly has factory functions — no more mixing.
Migration
Before:
const { UserError, UserErr } = createTaggedError("UserError").withContext<{ userId: string; }>(); // ❌ Error: factories not available without .withMessage()
After:
const { UserError, UserErr } = createTaggedError("UserError") .withContext<{ userId: string }>() .withMessage(({ context }) => `User ${context.userId} failed`); // ✅ Factories now available