# components/report-error (zidane-ui)

Import: `import { … } from 'zidane-ui'`. Source: [ui/src/components/report-error.ts](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts).

## Functions

### `configureErrorReports`

Function.

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

```ts
function configureErrorReports(options: ErrorReportOptions): void
```

**Parameters**

- `options` (`ErrorReportOptions`): The sink and the stacks switch.

Source: [ui/src/components/report-error.ts:42](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts#L42)

### `errorMessage`

Function.

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

```ts
function errorMessage(error: unknown): string
```

**Parameters**

- `error` (`unknown`): Anything thrown.

**Returns** `string`

Source: [ui/src/components/report-error.ts:76](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts#L76)

### `errorStacksShown`

Function.

Whether the error fallbacks show stacks ([`configureErrorReports`](https://zidane.si/docs/reference/ui-components-report-error.md#configureErrorReports)).

```ts
function errorStacksShown(): boolean
```

**Returns** `boolean`

Source: [ui/src/components/report-error.ts:48](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts#L48)

### `installRendererErrorHandlers`

Function.

Logs the window's uncaught errors and unhandled rejections through
[`reportRendererError`](https://zidane.si/docs/reference/ui-components-report-error.md#reportRendererError). Listens only: nothing is `preventDefault`ed,
so the browser's own reporting is untouched. Idempotent; returns the
uninstall.

```ts
function installRendererErrorHandlers(target?: Window): () => void
```

**Parameters**

- `target?` (`Window`, default `window`): The window to listen on (default `window`).

**Returns** `() => void`

Source: [ui/src/components/report-error.ts:125](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts#L125)

### `reportRendererError`

Function.

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

```ts
function reportRendererError(
  error: unknown,
  context: { componentStack?: string | null; source: string },
): void
```

**Parameters**

- `error` (`unknown`): Anything thrown.
- `context` (`{ componentStack?: string | null; source: string }`): `source` names what caught it ("Sidebar crashed"); `componentStack` is React's.

Source: [ui/src/components/report-error.ts:88](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts#L88)

### `resetReportedErrors`

Function.

Forgets what was reported. Tests only.

```ts
function resetReportedErrors(): void
```

Source: [ui/src/components/report-error.ts:111](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts#L111)

## Interfaces

### `ErrorReport`

Interface.

One distinct failure, as handed to the sink.

```ts
interface ErrorReport
```

**Properties**

- `componentStack?` (`string`): React's component stack, for an error a boundary caught.
- `message` (`string`): `Name: message` (or the thrown value's string form).
- `source` (`string`): What caught it: "Sidebar crashed", "uncaught error", "unhandled rejection".
- `stack?` (`string`): The JS stack, when the error had one.

Source: [ui/src/components/report-error.ts:11](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts#L11)

### `ErrorReportOptions`

Interface.

What [`configureErrorReports`](https://zidane.si/docs/reference/ui-components-report-error.md#configureErrorReports) sets.

```ts
interface ErrorReportOptions
```

**Properties**

- `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.

Source: [ui/src/components/report-error.ts:26](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts#L26)

## Types

### `ErrorReportSink`

Type.

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

```ts
type ErrorReportSink = (report: ErrorReport) => void
```

Source: [ui/src/components/report-error.ts:23](https://github.com/Tahul/zidane/blob/main/ui/src/components/report-error.ts#L23)
