> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nika.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> Tell a refused run, a failed run and a broken connection apart: three channels, each handled differently.

## Three channels

| What happened | Where it arrives | Handle it by |
| - | - | - |
| A check found problems | `check()` resolves `clean: false` with the findings | showing the engine's findings |
| The engine refused the run before it started: a red check, a cost floor above `maxCostUsd`, bad inputs, an unreadable file | `run()` **throws** `NikaOperationError`; no run exists | reading `error.code` and `error.findings` |
| The engine admitted the run, then it failed, paused or was refused late (no provider access `NIKA-1800`; over HTTP, a cost floor above the server's ceiling `NIKA-1709`) | `run.result()` **resolves** with `status: 'failed'` (or `paused`, `cancelled`, `interrupted`) | branching on `result.status` and `result.error.code` |
| Configuration, compatibility, transport or protocol trouble, or a lost observation | the promise **rejects** with a typed `NikaError` | catching the typed error; the run may still be running |

```ts errors.mts theme={"system"}
import { Nika, NikaOperationError, isNikaRunSucceeded } from '@supernovae-st/nika'

const nika = new Nika({ cwd: process.cwd() })

async function attempt(file: string) {
  try {
    const run = await nika.run(file)
    const result = await run.result() // admitted: a failure here is result data
    if (!isNikaRunSucceeded(result)) return `${file}: ${result.status} ${result.error?.code}`
    return `${file}: succeeded`
  } catch (error) {
    if (error instanceof NikaOperationError && error.operation === 'run') {
      return `${file}: refused ${error.code} (status ${error.status})`
    }
    throw error // configuration, transport, protocol: not about the workflow
  }
}

console.log(await attempt('hello.nika'))
console.log(await attempt('failing.nika'))
console.log(await attempt('list-notes.nika'))
```

```text theme={"system"}
hello.nika: succeeded
failing.nika: failed NIKA-BUILTIN-ASSERT-001
list-notes.nika: refused NIKA-SEC-004 (status 2)
```

`failing.nika` is on the [results page](https://docs.nika.sh/sdk/runtime/results.md);
`list-notes.nika` runs `ls` under `permits: {}`, see
[permits](https://docs.nika.sh/sdk/runtime/permits.md).

<video controls muted playsInline preload="none" poster="/images/posters/sdk-check-refused.png" aria-label="node gate.mts list-files.nika, a file that runs ls -1 under permits: {}, prints check refused · exit 2, NIKA-SEC-004 and the fix add ls to permits.exec, then run not started · NIKA-SEC-004 · no run, no events, no trace; the rest of the recording fixes the permits, then seals, verifies and tampers with a run" alt="node gate.mts list-files.nika, a file that runs ls -1 under permits: {}, prints check refused · exit 2, NIKA-SEC-004 and the fix add ls to permits.exec, then run not started · NIKA-SEC-004 · no run, no events, no trace; the rest of the recording fixes the permits, then seals, verifies and tampers with a run">
  <source src="https://mintcdn.com/supernovae-acdf3706/BQMaEHUNhf9JYml1/videos/sdk-admitted-executed-sealed.mp4?fit=max&auto=format&n=BQMaEHUNhf9JYml1&q=85&s=f6f4fa573c7038750c954f0914033da5" type="video/mp4" />
</video>

**A refusal is not a run.** The poster is the first screen of the recording: `list-files.nika` runs `ls -1` under `permits: {}`, like `list-notes.nika`. `check()` returns the refusal (`exit 2`, `NIKA-SEC-004`) with its fix, and `run()` rejects with `NikaOperationError`, so no run, events or trace exist. Press play for the rest: the one-line fix, then an unsealed run, a sealed one and a tampered trace, which [Receipts](https://docs.nika.sh/sdk/runtime/receipts.md) explains. *Recorded in a terminal from `@supernovae-st/nika` 0.123.0 and its bundled engine `nika 0.123.0 (0bfde3765)`; every model call is `mock/echo`, the engine's offline rehearsal model, with no provider key and no network.*

> [accordion] Transcript: every screen of the recording, in order
>
> ```text theme={"system"}
> $ cat list-files.nika                          # a teammate's file: runs ls, permits nothing
> nika: list-files
> model: mock/echo
> permits: {}
> tasks:
>   list:
>     exec:
>       command: ["ls", "-1"]
> outputs:
>   files: ${{ tasks.list.output }}
> $ node gate.mts list-files.nika
> check  refused · exit 2
>        NIKA-SEC-004
>        exec task under a boundary that forbids shells (task `list`) — fix: add "ls" to permits.exec
> run    not started · NIKA-SEC-004 · no run, no events, no trace
> $
>
> ── screen cleared ──
>
> $ diff -u list-files.nika fixed/list-files.nika
> --- list-files.nika     2026-10-24 19:02:08
> +++ fixed/list-files.nika       2026-10-24 19:02:08
> @@ -1,6 +1,7 @@
>  nika: list-files
>  model: mock/echo
> -permits: {}
> +permits:
> +  exec: [ls]
>  tasks:
>    list:
>      exec:
> $ node gate.mts fixed/list-files.nika
> check  clean · exit 0
> run    succeeded · 10 entries listed
> $
>
> ── screen cleared ──
>
> $ node prove.mts                     # this machine has no signing key yet
> run      succeeded · mock(echo) · Say hello from the Nika SDK.
> receipt  sealed false · 5 events · head 0135b1202a1d…
> verify   not verified · invalid · receipt_mismatch
> $ NIKA_KEYCHAIN=off ./node_modules/.bin/nika key init   # quick start, step 1
> run-signing key minted · fingerprint 847bf18789d52318
>   every run on this machine now seals its journal (verify: nika trace verify <file>)
> $ node prove.mts
> run      succeeded · mock(echo) · Say hello from the Nika SDK.
> receipt  sealed true · 6 events · head b69360abfef1…
> verify   verified
> $ node tamper.mts
> changed one byte on line 4 of .nika/traces/2026-10-24T15-02-41Z-7b95.ndjson
> $ node verify.mts                             # later, from the receipt you stored
> verify   not verified · invalid
> engine   BROKEN at line 5 — recorded chain bb6c5faae667604f · computed fe7aa85e4fead3cc
> $
> ```

## `NikaOperationError`

The engine refused an operation. Over the local transport:

* `code` is the engine's own: the first check finding that names one
  (`NIKA-SEC-004`, `NIKA-PARSE-005`, `NIKA-AUTH-006`…) or the refusal's code
  (`NIKA-1709`, `NIKA-1708`). When the engine named none, as for an unreadable
  file or a cloud model the catalog cannot price (`price unknown: …`), `code`
  is the SDK's `run_refused`.
* `findings` holds the engine's check findings untouched (`code`, `message`,
  `severity`, `gate`, `kind`, `task`). A budget or launch refusal has none.
* `status` is the engine's **exit code**: `2` for the file or its cost floor,
  `3` for the environment, the inputs or an unpriced cloud model.
* `operation` names the refused call (`run`, `check`, `compile`…).

Over HTTP, a refusal the server types as `{ error: { code, message } }`
becomes a `NikaOperationError` whose `status` is the **HTTP status** (`404`
not found, `409` conflict, `412` stale schedule revision, `422` refused) and
whose `code` is the server's (`not_found`, `idempotency_conflict`,
`schedule_conflict`, a stamped `NIKA-…` admission code). The artifact
methods add theirs (`job_not_settled`, `artifact_journal_unverified`,
`artifact_changed`, `403` `artifact_too_large`, `503` `artifact_capacity`…),
with `operation` `artifacts`, `downloadArtifact` or `readArtifact`
([Outputs and artifacts](https://docs.nika.sh/sdk/remote/artifacts.md#refusals)). Messages carry no
paths, and a reflected bearer token is redacted.

A frame or document larger than `machineBufferBytes` (16 MiB by default) is a
`NikaProtocolError` whose message names the option and the size to set.

## The error tree

Every error the SDK raises for an engine, transport, configuration or
compatibility problem extends `NikaError`:

```text theme={"system"}
NikaError
├── NikaConfigurationError       // an invalid option, or an inputs value JSON cannot carry
├── NikaEngineUnavailable        // no engine for this host (code NIKA_ENGINE_UNAVAILABLE, platform, arch)
├── NikaTransportError
│   ├── NikaProtocolError        // output that proves neither an admission nor a refusal
│   └── NikaObservationInterrupted   // this client lost its view; the run may still be live
├── NikaCompatibilityError       // the engine or server lacks a capability (capability names it)
├── NikaOperationError           // the engine refused an operation, with its code and findings
├── NikaEventBufferOverflowError // one event view hit its bound; never about the run
└── NikaRunOwnershipError        // a deprecated wrapper was given another client's run
```

Misusing the API itself (an empty workflow name, a negative event cursor, a
receipt that is not an object) throws a plain `TypeError` or `RangeError`
before any engine or network work starts.

> [!WARNING]
>
> Over HTTP, `traceVerify(receipt)` can resolve `verdict: "unavailable"` when the
> server holds no journal for a job (refused before its first event, or still
> queued). That typed verdict is not a transport error and must not be
> converted into one.

> [accordion] Which version is this?
>
> > [!NOTE]
> >
> > These pages describe the published `@supernovae-st/nika@0.124.4`
> > [SDK release](https://github.com/supernovae-st/nika-client/tree/v0.124.4) and its matching
> > [bundled engine](https://github.com/supernovae-st/nika/releases/tag/v0.124.4). A newer engine
> > release or SDK main commit does not change an installed package. Use Node.js
> > 22 or newer, on macOS (arm64, x64) or Linux with glibc (x64, arm64); no
> > global Nika installation is required for local mode. Versioned transcripts,
> > recordings and measurements keep the release they were captured on;
> > selecting this package release does not re-run those examples.

> [card] [Results](https://docs.nika.sh/sdk/runtime/results.md)
>
> Every status an admitted run can end on.

> [card] [Type index](https://docs.nika.sh/sdk/reference/types.md)
>
> Every exported result and error type.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.