Base class for all errors used in Result<T, E>.
BaseError(message: string,options?: BaseErrorOptions)
TData extends BaseErrorSchema = BaseErrorSchema
The serialized data type for this error
traceIdGetter: (() => string | undefined) | undefined
Optional callback to provide a trace ID from ambient context (e.g. OpenTelemetry).
Trellis (or other consumers) can set this once at startup so all BaseError instances capture a traceId automatically unless explicitly provided.
baseSerializable(): BaseErrorSchema
Helper method to get base serializable fields. Subclasses should use this to build their complete serializable object.
getContext(): Record<string, unknown>
Get the current context object.
getTraceId(): string | undefined
Get the trace ID for this error. Returns the trace ID captured at error creation time.
toJSON(): string
Serializes error to JSON string.
toSerializable(): TData
Serializes error to a plain object. Subclasses must implement this to return their specific data type.
withContext(context?: Record<string, unknown>): this
Add contextual information to this error. Useful for adding runtime context like request IDs, user IDs, etc.
withTraceId(traceId: string | undefined): this
Attach a trace ID if one was not captured when the error was created.