Error Handling System
Error Handling System
Relevant source files
The following files were used as context for generating this wiki page:
The Primebrick Frontend implements a centralized error management pipeline designed to handle both local application errors and standardized backend responses. It utilizes a ring-buffer store for history, a multi-tier impact taxonomy, and a dedicated UI for deep inspection of complex error payloads.
Impact Level Taxonomy
Errors are classified using an ImpactLevel to determine their visual priority and notification style src/lib/errors/app-errors.ts:7-7.
| Level | Description | UI Toast Variant | Sidebar Badge Tone |
|---|---|---|---|
CRITICAL | System-wide failure or data loss risk. | toast.critical (Semaphore Red) | danger |
HIGH | Standard functional error (e.g., API 500). | toast.error (Destructive) | danger |
MEDIUM | Warning or non-blocking issue. | toast.warning (Amber) | warning |
LOW | Informational or background notification. | toast.info (Sky Blue) | info |
Sources: src/lib/errors/app-errors.ts:54-76, src/lib/shell/sheets/panels/ErrorsPanel.svelte:54-80
The Error Pipeline
The system centralizes all errors into the appErrors writable store, which maintains a ring buffer capped at 50 entries to prevent memory leaks src/lib/errors/app-errors.ts:15-35.
Data Flow Diagram
This diagram illustrates the transition from raw error triggers to UI representation.
Code
Sources: src/lib/errors/app-errors.ts:82-103, src/lib/errors/app-errors.ts:166-197, src/lib/shell/sheets/panels/ErrorsPanel.svelte:9-9
RFC 7807 Problem Details
The backend communicates errors using the RFC 7807 (Problem Details for HTTP APIs) standard. The frontend consumes this via the RFC7807Error interface src/lib/errors/rfc7807.ts:5-20.
Mapping and Translation
When a backend error is received:
- Severity Mapping: The
severityfield is mapped to anImpactLevel(defaulting toHIGH) src/lib/errors/app-errors.ts:153-159. - Key Translation:
mapRFC7807ToMessageKeychecksstatusandinternal_codeto return a user-friendly i18n key (e.g., mappingaccount_lockedtologin.accountLocked) src/lib/errors/rfc7807-mapper.ts:7-36. - Preservation: Any non-standard fields (like
duplicateResultsorissues) are preserved in theextraFieldsobject for the detailed viewer src/lib/errors/app-errors.ts:179-196.
UI Components
ErrorsPanel (src/lib/shell/sheets/panels/ErrorsPanel.svelte)
A global side-sheet that displays the history of appErrors.
- Uses
EventCardcomponents to display error metadata, scope, and timestamps src/lib/shell/sheets/panels/ErrorsPanel.svelte:136-190. - Provides a "Clear All" action via
clearAppErrors()src/lib/shell/sheets/panels/ErrorsPanel.svelte:87-98. - Triggers the
RfcErrorDialogfor entries containingextradata src/lib/shell/sheets/panels/ErrorsPanel.svelte:191-201.
RfcErrorDialog (src/lib/components/ui/rfc-error-dialog.svelte)
A full-screen modal used for deep inspection of complex errors.
- Aesthetic Mode: Uses
JsonTableViewerto render structured data in a readable, recursive table format src/lib/components/ui/rfc-error-dialog.svelte:155-161. - Raw Mode: Uses the
shikihighlighter to display the raw JSON payload with syntax highlighting src/lib/components/ui/rfc-error-dialog.svelte:56-78. - Navigation: Includes a
Dockto switch between preview modes src/lib/components/ui/rfc-error-dialog.svelte:123-144.
Code Entity Association
This diagram maps system behaviors to the specific code entities responsible for the error lifecycle.
Code
Sources: src/lib/errors/app-errors.ts:166-166, src/lib/errors/rfc7807-mapper.ts:7-7, src/lib/components/ui/rfc-error-dialog.svelte:1-1, src/lib/components/toasts/EventToast.svelte:1-1
Key Functions Reference
| Function | Purpose | File |
|---|---|---|
pushAppError | Pushes a simple string-based error to the store and shows a toast. | src/lib/errors/app-errors.ts:87-103 |
pushImpactError | Pushes a categorized error with support for i18n keys and extra metadata. | src/lib/errors/app-errors.ts:105-143 |
pushRFC7807Error | Transforms a standard backend error response into an AppError. | src/lib/errors/app-errors.ts:166-197 |
toast.critical | Displays a high-priority, persistent notification using TOAST_CRITICAL_CLASS. | src/lib/errors/toast.ts:57-62 |
mapSeverityToImpact | Normalizes backend severity strings into ImpactLevel types. | src/lib/errors/app-errors.ts:153-159 |
Sources: src/lib/errors/app-errors.ts:1-197, src/lib/errors/toast.ts:1-76