# HostFailure

An error with a failure kind and a flag that tells the host whether a retry can succeed.

`open` throws `HostFailure` with kind `configuration` and `permanent` set when the SDK refuses the runtime configuration, so the host can fail the turn instead of retrying it. Hosts also construct `HostFailure` for their own classifications.

```ts title="host.ts"
import {
  HostFailure,
  type AgentConfiguration,
  type AgentRuntime,
  type RuntimeOptions,
} from 'nanocode-wasm'

declare const runtime: AgentRuntime
declare const options: RuntimeOptions
declare const config: AgentConfiguration

try {
  await runtime.open(
    { ...config, model: 'gpt-6-luna', provider: 'claude' },
    options,
  )
} catch (error) {
  // configuration true: a Codex model in a Claude session
  if (error instanceof HostFailure)
    console.log(error.kind, error.permanent)
}
```

## Signature

```ts
class HostFailure extends Error {
  readonly kind: string
  readonly permanent: boolean
  constructor(message: string, kind: string, permanent: boolean)
}
```

## Parameters

### message

* **Type:** `string`

The error message. For a refused configuration, it is the SDK's reason, such as a model that is not a Claude model.

```ts
import { HostFailure } from 'nanocode-wasm'

// A host classification with its own message
const failure = new HostFailure('the hand was revoked', 'revoked', true)
```

### kind

* **Type:** `string`

The failure kind. The package sets `'configuration'`. Hosts choose their own kinds.

```ts
import { HostFailure } from 'nanocode-wasm'

declare const error: HostFailure

// Shows configuration failures to the session owner
if (error.kind === 'configuration') console.error(error.message)
```

### permanent

* **Type:** `boolean`

`true` when a retry with the same input fails the same way.

```ts
import { HostFailure } from 'nanocode-wasm'

// A transient failure that the host retries
const failure = new HostFailure('the store is busy', 'storage', false)
```

## Returns

`new HostFailure(message, kind, permanent)` returns an `Error` with `kind` and `permanent` set.

```ts
import { HostFailure } from 'nanocode-wasm'

// true
console.log(
  new HostFailure('refused', 'configuration', true) instanceof Error,
)
```

## Errors

The constructor does not throw.

```ts
import { HostFailure } from 'nanocode-wasm'

// Throws the failure for a caller to classify
throw new HostFailure('refused', 'configuration', true)
```
