Skip to content

components/report-error

import { … } from 'zidane-ui'ui/src/components/report-error.ts

Functions#

configureErrorReportsFunction#

Sets the sink and whether fallbacks show stacks. Call once at boot, before the first render; fields left out keep their value.

TypeScript
function configureErrorReports(options: ErrorReportOptions): void
Parameters
NameTypeDescription
optionsErrorReportOptions

The sink and the stacks switch.

ui/src/components/report-error.ts:42

errorMessageFunction#

An error's message for a person: the Error's message (its name when empty), else its string form.

TypeScript
function errorMessage(error: unknown): string
Parameters
NameTypeDescription
errorunknown

Anything thrown.

string

ui/src/components/report-error.ts:76

errorStacksShownFunction#

Whether the error fallbacks show stacks (configureErrorReports).

TypeScript
function errorStacksShown(): boolean
boolean

ui/src/components/report-error.ts:48

installRendererErrorHandlersFunction#

Logs the window's uncaught errors and unhandled rejections through reportRendererError. Listens only: nothing is preventDefaulted, so the browser's own reporting is untouched. Idempotent; returns the uninstall.

TypeScript
function installRendererErrorHandlers(target?: Window): () => void
Parameters
NameTypeDefaultDescription
target?Windowwindow

The window to listen on (default window).

() => void

ui/src/components/report-error.ts:125

reportRendererErrorFunction#

Logs error to the console and the sink unless the same one was already reported. Never throws, never swallows (it only logs).

TypeScript
function reportRendererError(
  error: unknown,
  context: { componentStack?: string | null; source: string },
): void
Parameters
NameTypeDescription
errorunknown

Anything thrown.

context{ componentStack?: string | null; source: string }

source names what caught it ("Sidebar crashed"); componentStack is React's.

ui/src/components/report-error.ts:88

resetReportedErrorsFunction#

Forgets what was reported. Tests only.

TypeScript
function resetReportedErrors(): void

ui/src/components/report-error.ts:111

Interfaces#

ErrorReportInterface#

One distinct failure, as handed to the sink.

TypeScript
interface ErrorReport
ErrorReport properties
NameTypeDescription
componentStack?string

React's component stack, for an error a boundary caught.

messagestring

Name: message (or the thrown value's string form).

sourcestring

What caught it: "Sidebar crashed", "uncaught error", "unhandled rejection".

stack?string

The JS stack, when the error had one.

ui/src/components/report-error.ts:11

ErrorReportOptionsInterface#

What configureErrorReports sets.

TypeScript
interface ErrorReportOptions
ErrorReportOptions properties
NameTypeDescription
showStacks?boolean

The error fallbacks show the JS and component stacks (a development build).

sink?ErrorReportSink | null

Receives each distinct report; null for the console only.

ui/src/components/report-error.ts:26

Types#

ErrorReportSinkType#

Where reports go besides the console (an app's log).

TypeScript
type ErrorReportSink = (report: ErrorReport) => void

ui/src/components/report-error.ts:23