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

# Function: unwrapError()

Extracts the error value from a [Result](/byethrow/api/types/Result.Result.md) or [ResultAsync](/byethrow/api/types/Result.ResultAsync.md).

If the input is a [Success](/byethrow/api/types/Result.Success.md), it will throw the success value or return the default value if provided.

## Type Param

**R**

The input [Result](/byethrow/api/types/Result.Result.md) or [ResultAsync](/byethrow/api/types/Result.ResultAsync.md).

## Type Param

**T**

The default value type (optional).

## Examples

**Failure Case (without default)**

```ts
import { Result } from '@praha/byethrow';

const result: Result.Result<number, string> = Result.fail('Oops');
const error = Result.unwrapError(result); // 'Oops'
```

**Failure Case (with default)**

```ts
import { Result } from '@praha/byethrow';

const result: Result.Result<number, string> = Result.fail('Oops');
const error = Result.unwrapError(result, 'default'); // 'Oops'
```

**Success Case (without default)**

```ts
import { Result } from '@praha/byethrow';

const result: Result.Result<number, string> = Result.succeed(100);
const error = Result.unwrapError(result); // throws 100
```

**Success Case (with default)**

```ts
import { Result } from '@praha/byethrow';

const result: Result.Result<number, string> = Result.succeed(100);
const error = Result.unwrapError(result, 0); // 0
```

## See

[assertFailure](/byethrow/api/functions/Result.assertFailure.md) - When used with [assertFailure](/byethrow/api/functions/Result.assertFailure.md), you can safely unwrap the [Result](/byethrow/api/types/Result.Result.md).

## Call Signature

> **unwrapError**\<`R`>(`result`): `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<[`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>> : [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>

### Type Parameters

#### R

`R` _extends_ [`ResultMaybeAsync`](/byethrow/api/types/Result.ResultMaybeAsync.md)\<`any`, `any`>

### Parameters

#### result

`R`

### Returns

`true` _extends_ `HasPromise`\<`R`> ? `Promise`\<[`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>> : [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>

## Call Signature

> **unwrapError**\<`R`, `T`>(`result`, `defaultValue`): `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<`T` | [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>> : `T` | [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>

### Type Parameters

#### R

`R` _extends_ [`ResultMaybeAsync`](/byethrow/api/types/Result.ResultMaybeAsync.md)\<`any`, `any`>

#### T

`T`

### Parameters

#### result

`R`

#### defaultValue

`T`

### Returns

`true` _extends_ `HasPromise`\<`R`> ? `Promise`\<`T` | [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>> : `T` | [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>

## Call Signature

> **unwrapError**\<`R`>(): (`result`) => `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<[`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>> : [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>

### Type Parameters

#### R

`R` _extends_ [`ResultMaybeAsync`](/byethrow/api/types/Result.ResultMaybeAsync.md)\<`any`, `any`>

### Returns

(`result`) => `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<[`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>> : [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>

## Call Signature

> **unwrapError**\<`R`, `T`>(`defaultValue`): (`result`) => `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<`T` | [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>> : `T` | [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>

### Type Parameters

#### R

`R` _extends_ [`ResultMaybeAsync`](/byethrow/api/types/Result.ResultMaybeAsync.md)\<`any`, `any`>

#### T

`T`

### Parameters

#### defaultValue

`T`

### Returns

(`result`) => `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<`T` | [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>> : `T` | [`InferFailure`](/byethrow/api/types/Result.InferFailure.md)\<`R`>
