v0.28.0
Minor Changes
-
7c41baf: feat(error): explicit opt-in for context and cause properties
Following Rust's thiserror pattern,
createTaggedErrornow uses explicit opt-in forcontextandcauseproperties. By default, errors only have{ name, message }.Breaking Change: Previously, all errors had optional
contextandcauseproperties by default. Now you must explicitly chain.withContext<T>()and/or.withCause<T>()to add these properties.Before (old behavior):
const { ApiError } = createTaggedError("ApiError"); // ApiError had: { name, message, context?: Record<string, unknown>, cause?: AnyTaggedError }
After (new behavior):
// Minimal error - only name and message const { ApiError } = createTaggedError("ApiError"); // ApiError has: { name, message } // With required context const { ApiError } = createTaggedError("ApiError").withContext<{ endpoint: string; }>(); // ApiError has: { name, message, context: { endpoint: string } } // With optional typed cause const { ApiError } = createTaggedError("ApiError").withCause< NetworkError | undefined >(); // ApiError has: { name, message, cause?: NetworkError }
Migration: To replicate the old permissive behavior, either specify the types explicitly:
const { FlexibleError } = createTaggedError("FlexibleError") .withContext<Record<string, unknown> | undefined>() .withCause<AnyTaggedError | undefined>();
Or use the new defaults by calling without generics:
const { FlexibleError } = createTaggedError("FlexibleError") .withContext() // Defaults to Record<string, unknown> | undefined .withCause(); // Defaults to AnyTaggedError | undefined