> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Utf8ErrorFunc

```ts theme={null}
type Utf8ErrorFunc: (reason, offset, bytes, output, badCodepoint?) => number;
```

A callback that can be used with [**toUtf8String**](https://docs.qu.ai/sdk/content/functions/toUtf8String.md) to analysis or recovery from invalid UTF-8
data.

Parsing UTF-8 data is done through a simple Finite-State Machine (FSM) which calls the `Utf8ErrorFunc` if a fault is
detected.

The `reason` indicates where in the FSM execution the fault occurred and the `offset` indicates where the input
failed.

The `bytes` represents the raw UTF-8 data that was provided and `output` is the current array of UTF-8 code-points,
which may be updated by the `Utf8ErrorFunc`.

The value of the `badCodepoint` depends on the `reason`. See [**Utf8ErrorReason**](https://docs.qu.ai/sdk/content/type-aliases/Utf8ErrorReason.md) for
details.

The function should return the number of bytes that should be skipped when control resumes to the FSM.

## Parameters

| Parameter | Type |
| :- | :- |
| `reason` | [`Utf8ErrorReason`](https://docs.qu.ai/sdk/content/type-aliases/Utf8ErrorReason) |
| `offset` | `number` |
| `bytes` | `Uint8Array` |
| `output` | `number`\[] |
| `badCodepoint`? | `number` |

## Returns

`number`

## Source

[encoding/utf8.ts:74](https://github.com/dominant-strategies/quais.js/blob/c1c12d43f9d34c6baad2b0542bd6d0acd6fefcbf/src/encoding/utf8.ts#L74)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.