# mapWireSerializationError

> **mapWireSerializationError**<`Code`, `T`>(`codes`, `makeError`, `detail`, `write`): `T`

Defined in: [packages/wire/src/serialization-errors.ts:37](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/wire/src/serialization-errors.ts#L37)

Run one write, translating every `knotkit/wire` caller-contract failure into the package’s own error and code.

Wire rejects a caller contract for four reasons a structure package must restate in its own closed list: an argument out of range (`INVALID_ARGUMENT`), an unpaired surrogate with no strict UTF-8 encoding (`INVALID_STRING`), a codec returning malformed bytes (`INVALID_CODEC_RESULT`), and a codec mapping two distinct values to identical bytes (`NON_INJECTIVE_CODEC`). Without this mapping, a caller catching the package’s `InvalidInputError` would see a bare `WireInvalidInputError` escape instead, which breaks the package’s promise that every throw carries a code from its own list.

## Type Parameters

### Code

`Code` *extends* `string`

### T

`T`

## Parameters

### codes

[`WireSerializationCodeMap`](/reference/knotkit/wire/type-aliases/wireserializationcodemap/)<`Code`>

The package’s translation of each wire code.

### makeError

(`code`, `detail`) => [`KnotkitError`](/reference/knotkit/errors/classes/knotkiterror/)

Builds the package’s error from a translated code.

### detail

`string`

The operation named in the message, such as `heap artifact`.

### write

() => `T`

The write to run.

## Returns

`T`

## Throws

The package error selected by `codes` for a wire caller-contract failure; any other error is rethrown untouched.
