> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# toError

Coerces an unknown thrown value into a proper `Error` instance.

Handles the common cases where libraries throw non-`Error` values
(e.g. plain API response bodies, arrays, Maps) that would otherwise
serialize as `[object Object]` in error messages.

```typescript
try {
  await riskyCall()
} catch (thrown) {
  const error = toError(thrown)
  console.error(error.message)
}
```

## Usage

### `toError(thrown: unknown)`

Coerces an unknown thrown value into a proper `Error` instance.

Handles the common cases where libraries throw non-`Error` values
(e.g. plain API response bodies, arrays, Maps) that would otherwise
serialize as `[object Object]` in error messages.

```typescript
import { toError } from 'massaman'
// or:  import { toError } from 'massaman/conversion'

try {
  await riskyCall()
} catch (thrown) {
  const error = toError(thrown)
  console.error(error.message)
}
```

#### Parameters


thrownunknownrequired

the caught value to normalize.

#### Returns

An `Error` with a meaningful `.message`. If `thrown` is   already an `Error`, it is returned as-is. The original value is   preserved as `.cause` for debugging.

```typescript
Error
```
