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.
function configureErrorReports(options: ErrorReportOptions): voidParameters
| Name | Type | Description |
|---|---|---|
| options | ErrorReportOptions | The sink and the stacks switch. |
errorMessageFunction#
An error's message for a person: the Error's message (its name when empty), else its string form.
function errorMessage(error: unknown): stringParameters
| Name | Type | Description |
|---|---|---|
| error | unknown | Anything thrown. |
Returns
stringerrorStacksShownFunction#
Whether the error fallbacks show stacks (configureErrorReports).
function errorStacksShown(): booleanReturns
booleaninstallRendererErrorHandlersFunction#
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.
function installRendererErrorHandlers(target?: Window): () => voidParameters
| Name | Type | Default | Description |
|---|---|---|---|
| target? | Window | window | The window to listen on (default |
Returns
() => voidreportRendererErrorFunction#
Logs error to the console and the sink unless the same one was already reported. Never throws,
never swallows (it only logs).
function reportRendererError(
error: unknown,
context: { componentStack?: string | null; source: string },
): voidParameters
| Name | Type | Description |
|---|---|---|
| error | unknown | Anything thrown. |
| context | { componentStack?: string | null; source: string } |
|
resetReportedErrorsFunction#
Forgets what was reported. Tests only.
function resetReportedErrors(): voidInterfaces#
ErrorReportInterface#
One distinct failure, as handed to the sink.
interface ErrorReportProperties
| Name | Type | Description |
|---|---|---|
| componentStack? | string | React's component stack, for an error a boundary caught. |
| message | string |
|
| source | string | What caught it: "Sidebar crashed", "uncaught error", "unhandled rejection". |
| stack? | string | The JS stack, when the error had one. |
ErrorReportOptionsInterface#
What configureErrorReports sets.
interface ErrorReportOptionsProperties
| Name | Type | Description |
|---|---|---|
| showStacks? | boolean | The error fallbacks show the JS and component stacks (a development build). |
| sink? | ErrorReportSink | null | Receives each distinct report; |
Types#
ErrorReportSinkType#
Where reports go besides the console (an app's log).
type ErrorReportSink = (report: ErrorReport) => void