Common utilities for error handling within Backstage with structured error classes and serialization functions
63
Design a small error module that standardizes how domain-specific errors capture and surface their causes. The module should make it easy to produce meaningful error messages that automatically mention upstream failures while keeping error names aligned with their subclasses. Keep the API surface compact and centered on wrapping errors rather than general logging or formatting utilities.
Error("disk full") produces a message containing both snippets in order ("upload failed" then "disk full") and exposes the original Error as the cause property. @testcause property undefined. @testname matches the subclass name without extra work from the caller. @testcause value. @testunknown input returns it unchanged when it is already an Error, otherwise produces a new Error whose message includes either the provided string (e.g., "boom") or a fallback label like "Unexpected failure" when the value is nullish; the fallback message must not be empty. @test@generates
export interface CauseOptions {
cause?: unknown;
}
export class PipelineError extends Error {
constructor(message: string, options?: CauseOptions);
cause?: Error;
}
export class InvalidConfigError extends PipelineError {}
export class TaskFailedError extends PipelineError {}
export function ensureError(value: unknown, fallbackMessage?: string): Error;Provides a cause-aware base error utility and helpers for validating error-like values.
Install with Tessl CLI
npx tessl i tessl/npm-backstage--errorsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10