> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Bytes Errors

:::info
`Bytes` is a re-export of ox's [`Bytes`](https://oxlib.sh/api/Bytes/errors). Refer to the ox documentation for the full reference.
:::

## `Bytes.InvalidBytesBooleanError`

Thrown when the bytes value cannot be represented as a boolean.

### Examples

```ts twoslash
// @noErrors
import { Bytes } from 'viem/utils'

Bytes.toBoolean(Bytes.from([5]))
// @error: Bytes.InvalidBytesBooleanError: Bytes value `[5]` is not a valid boolean.
// @error: The bytes array must contain a single byte of either a `0` or `1` value.
```

## `Bytes.InvalidBytesTypeError`

Thrown when a value cannot be converted to bytes.

### Examples

```ts twoslash
// @noErrors
import { Bytes } from 'viem/utils'

Bytes.from('foo')
// @error: Bytes.InvalidBytesTypeError: Value `foo` of type `string` is an invalid Bytes value.
```

## `Bytes.SizeExceedsPaddingSizeError`

Thrown when a the padding size exceeds the maximum allowed size.

### Examples

```ts twoslash
// @noErrors
import { Bytes } from 'viem/utils'

Bytes.padLeft(Bytes.fromString('Hello World!'), 8)
// @error: [Bytes.SizeExceedsPaddingSizeError: Bytes size (`12`) exceeds padding size (`8`).
```

## `Bytes.SizeOverflowError`

Thrown when a size exceeds the maximum allowed size.

### Examples

```ts twoslash
// @noErrors
import { Bytes } from 'viem/utils'

Bytes.fromString('Hello World!', { size: 8 })
// @error: Bytes.SizeOverflowError: Size cannot exceed `8` bytes. Given size: `12` bytes.
```

## `Bytes.SliceOffsetOutOfBoundsError`

Thrown when a slice offset is out-of-bounds.

### Examples

```ts twoslash
// @noErrors
import { Bytes } from 'viem/utils'

Bytes.slice(Bytes.from([1, 2, 3]), 4)
// @error: Bytes.SliceOffsetOutOfBoundsError: Slice starting at offset `4` is out-of-bounds (size: `3`).
```
