# Errors and result handling

libds's error model as an integrator meets it. Every public function
returns `ds_result_t`; this doc explains the shape, the codes you will see,
their detail-string lifetime, and how errors propagate through callbacks and the
pump.

## What this is not

- Not the impl-side error spec — that is
  [IERR], the
  source of truth for the full taxonomy and runtime invariants.

---

(NERR-1)=
## The `ds_result_t` shape [NERR.1]

(NERR-1-1)=
[NERR.1.1] Every libds call reports its outcome the same way: a status code,
and optionally a sentence for a human.

The status is a plain integer rather than an enumeration, and that is
deliberate -- the value is what travels, through an FFI boundary, a log line,
or whatever transport the integrator builds ([RARC.3.3.3]), unchanged. Zero is success, negatives are errors, and
positives are unused ([NERR.1.3]). The code's **number** is the normative
part; a symbolic name is this implementation's convenience, and another
implementation is free to spell it however its language prefers so long as the
number and the meaning stay put ([IERR.2]).

The detail is the diagnostic half: short English, present or absent, and never
something to branch on ([NERR.1.2]).

*see also:* [IERR.2](#IERR-2), [RARC.3.3.3](#RARC-3-3-3), [NERR.1.2](#NERR-1-2), [NERR.1.3](#NERR-1-3)

(NERR-1-2)=
[NERR.1.2] **Check `status`, log `detail`.** Branching on `detail` text is
brittle — the strings are not stable across versions. Branch on `status`; when
you log, include `detail` for the operator.

(NERR-1-3)=
[NERR.1.3] `DS_OK` is `0`; anything negative is an error. Positive values are
unused. `DS_OK_R` and `DS_ERR_R(code, "detail")` are convenience macros in
`libds.h`.

---

(NERR-2)=
## Detail-string lifetime [NERR.2]

(NERR-2-1)=
[NERR.2.1] The `detail` string is owned by libds (or is a static literal).
**Treat it as valid only until your next call into libds on the same engine.**
Copy it before the next call if you must retain it (alerting pipeline, log
forwarder). A call that acts on no engine, such as a `ds_json_*` call or a
`ds_engine_new` that fails, returns a detail valid for the life of the process
([IERR.4.1.1]).

*see also:* [IERR.4.1.1](#IERR-4-1-1)

(NERR-2-2)=
[NERR.2.2] In practice nearly all detail strings are process-lifetime literals;
the "valid until next call" rule covers the few dynamically-built diagnostics
without forcing you to know which is which.

(NERR-2-3)=
[NERR.2.3] `detail` may be `NULL` when the status is `DS_OK` or
`DS_ERR_OOM`. With every other status libds sets it to a string ([IERR.3.3]).
The integrator **must** check it for `NULL` before passing it to `printf` or
anything else that reads it.

---

*ratified*  —  *see also:* [IERR.3.3](#IERR-3-3)

(NERR-3)=
## Code ranges [NERR.3]

(NERR-3-1)=
[NERR.3.1] **Status codes are grouped by number, by the concern that raises
them.** This table is the grouping, and the only statement of it. A code is its
number and its name; the group it falls in describes it.

| Range | Category |
|---|---|
| `0` | OK |
| `-1..-99` | Generic |
| `-100..-199` | Input |
| `-200..-299` | Runtime |
| `-300..-399` | Reserved: no code is produced or reused |
| `-400..-499` | Storage / callbacks |
| `-500..-549` | DSC container load |
| `-550..-599` | AOT code load |
| `-600..-625` | Native Rete, realtime and series-backend ABI |
| `-700..-704` | Dialect / artefact binding |
| `-710..-714` | Realtime contract |
| `-720..-730` | Event trace |
| `-10000` and below | Integrator-defined; an implementation never returns one |

Compiler diagnostics are not status codes ([RTCT.9.1]).

*see also:* [RTCT.9.1](#RTCT-9-1)

(NERR-4)=
## Generic errors [NERR.4]

| Code | Meaning |
|---|---|
| `DS_ERR_INVAL`       | NULL pointer to a non-optional argument; invalid enum; out-of-range integer |
| `DS_ERR_OOM`         | allocation failed inside libds; its detail may be NULL ([NERR.2.3]) |
| `DS_ERR_NOT_FOUND`   | required lookup miss (e.g. `ds_engine_schema_at` out of range) |
| `DS_ERR_STATE`       | rejected by current engine state (e.g. `ds_engine_clock_set` in live mode; **any** call from inside a callback into the engine that invoked it, a pump's or an enumerating read's, [RARC.13.16], [RARC.13.17]; a second `ds_engine_load_dsc` on one engine, [NFCT.1.1]) |
| `DS_ERR_OVERFLOW`    | a bounded queue / counter would overflow (internal boundaries) |
| `DS_ERR_UNSUPPORTED` | an operation unavailable in this build (e.g. `ds_engine_mem` is RETE-only) |
| `DS_ERR_INTERNAL`    | invariant violation inside libds — a bug; file an issue with the detail |
| `DS_ERR_IO`          | an integrator callback (a recording sink, a storage backend, [NSTG.3.3]) reports a failure of its own I/O. libds performs no I/O and raises it nowhere itself; the call whose callback returned it returns it ([NCBK.1.5]) |
| `DS_ERR_ENGINE_HALTED` | an `EngineError` halted the tier, or a load failed ([RDSC.9.8]). Returned by the call that raised the `EngineError`, and by every later call but the few [NCBK.2.9] leaves valid, which does nothing; a failed load returns its own code. Returned whatever caused the halt — the cause is carried by the `EngineError` or the failed load's status, not by this code ([NCBK.2.9]) |

*see also:* [NCBK.1.5](#NCBK-1-5), [NCBK.2.9](#NCBK-2-9), [NERR.2.3](#NERR-2-3), [NFCT.1.1](#NFCT-1-1), [NSTG.3.3](#NSTG-3-3), [RARC.13.16](#RARC-13-16), [RARC.13.17](#RARC-13-17), [RDSC.9.8](#RDSC-9-8)

(NERR-4-1)=
[NERR.4.1] **`DS_ERR_INVAL` is the most common code during integration** —
almost always a NULL where non-NULL was required, or an out-of-range enum. The
detail names the argument.

---

(NERR-5)=
## Input errors [NERR.5]

| Code | Meaning |
|---|---|
| `DS_ERR_PARSE`               | a DSC atom body, or `ds_json_parse` input, is malformed; JSON text in which one object repeats a key is malformed ([LGRA.5.8.7]), and so is JSON text holding an integer literal outside the 64-bit signed range ([LGRA.5.8.9]) or a float literal past the largest finite `Float` ([LGRA.5.8.10]) |
| `DS_ERR_SCHEMA_UNKNOWN`      | an action referenced a schema that isn't registered; or a replayed `FactAssert` names a schema the stream never announced or the engine does not hold ([RFCS.5.4]) |
| `DS_ERR_SLOT_UNKNOWN`        | a referenced slot is not on the schema |
| `DS_ERR_SLOT_TYPE_MISMATCH`  | a slot value's `kind` ≠ the schema's declared type (assert path), or a fact-ref whose schema ≠ the slot's `schema_ref` |

-102 and -105 to -108 are reserved and never reused ([IERR.2.4]).

---

*ratified*  —  *see also:* [IERR.2.4](#IERR-2-4), [LGRA.5.8.10](#LGRA-5-8-10), [LGRA.5.8.7](#LGRA-5-8-7), [LGRA.5.8.9](#LGRA-5-8-9), [RFCS.5.4](#RFCS-5-4)

(NERR-6)=
## Runtime errors [NERR.6]

| Code | Meaning |
|---|---|
| `DS_ERR_FACT_INVALID`     | `ds_engine_retract` was handed a fact handle that holds no fact. Every handle the engine hands out holds one, so a caller obeying [NFCT.3.2] does not meet this code. A handle whose fact is not live, or one another engine handed out, is not this code: passing one is undefined behaviour, and no status reports it ([IDAT.1.6]) |
| `DS_ERR_ACTION_FAILED`    | a callback's own report that it failed: the call that fired the callback returns it ([NCBK.1.5]). libds raises it for no condition of its own, and a `call` with no call callback is `DS_ERR_STORAGE_UNAVAILABLE` instead ([NERR.7]) |
| `DS_ERR_TIME_RANGE` (-205) | a `Time` outside the representable nanosecond range (≈1678–2262), or a `Date` outside the same range — a hard error, not a silent integer wrap (LTIM.1.1.5, LTIM.1.2.2) |
| `DS_ERR_NAN_REJECTED` (-216) | a NaN `Float` rejected at `ds_engine_assert`, or as a call argument, which refuses the call ([LEXP.4.2]) — NaN must not enter working memory or a payload; `Inf` is allowed. Increments `ds.facts.nan_rejected_total` |
| `DS_ERR_JSON_NONFINITE` (-217) | a host call that would put a non-finite `Float` (`±Inf`, or a NaN) into a `Json` value, such as `ds_json_new_float`, is refused with it and changes nothing; it holds no engine, so no metric moves ([LGRA.5.8.10]). A rule's path does not return this code. There a non-finite `Float` forced into a JSON data-plane body, the `cache` value or a `Json` call argument, is a `NOT_REPRESENTABLE` trap at the verb ([LDET.3.2.7]): the activation is abandoned there, the verb does not run, so no invalid `inf` token reaches the wire, and `ds.json.nonfinite_total{verb}` increments. The trap's `ComputationError` on the stream is its report ([NCBK.2.8]) |
| `DS_ERR_SERIES_NO_BACKING` (-218) | a series aggregation read that no *declared* backing can answer — the emit plan asked for a value nothing computes — or a read whose backing query failed. The rule still has to match on something, so it receives the aggregation's cold value (`LSER.19.8`) and the error is stashed, surfacing from `ds_engine_pump` rather than being returned from the read. Distinct from "no samples yet", which stays silent and is expected: backend instances allocate lazily (`LSER.9.1.1`) |
| `DS_ERR_SCHEMA_HASH_MISMATCH` (-219) | `ds_engine_assert_external` met a `FactExternal` whose `schema_hash` differs from the program's schema of that name — a record from a changed schema, read before migration ([NCBK.10.4]) |
| `DS_ERR_FACT_REF_CONFLICT` (-220) | `ds_engine_assert_external` met a nested fact reference whose key a different live fact already holds; nothing was asserted ([NCBK.10.4]) |
| `DS_ERR_JSON_LIMIT` (-221) | a `Json` value the host hands the engine — a slot value, JSON text to parse, a call response, a cache entry — would exceed one of its limits: depth, node count, string bytes, or text length ([LGRA.5.8.6]). The call is refused and changes nothing; nothing is truncated. The status is the whole refusal: no event is recorded |
| `DS_ERR_ENCODING` (-222) | text the host hands the engine is not well-formed UTF-8: a `String` slot value at `ds_engine_assert`, JSON text at `ds_json_parse`, a string or key at `ds_json_new_string` or `ds_json_object_set`, a seed at `ds_engine_cache_seed`, or a call's response ([LSTR.8.5]). The call is refused and changes nothing; nothing is repaired. The status is the whole refusal: no event is recorded |
| `DS_ERR_NOT_REPRESENTABLE` (-223) | a slot's unit conversion has no result for the number it was handed ([NFCT.1.4.6]). The call changes nothing |

-201 and -203 are reserved and never reused ([IERR.2.5]).

*see also:* [NFCT.3.2](#NFCT-3-2), [IDAT.1.6](#IDAT-1-6), [IERR.2.5](#IERR-2-5), [LDET.3.2.7](#LDET-3-2-7), [LEXP.4.2](#LEXP-4-2), [LGRA.5.8.10](#LGRA-5-8-10), [LGRA.5.8.6](#LGRA-5-8-6), [LSER.19.8](#LSER-19-8), [LSER.9.1.1](#LSER-9-1-1), [LSTR.8.5](#LSTR-8-5), [LTIM.1.1.5](#LTIM-1-1-5), [NCBK.1.5](#NCBK-1-5), [NCBK.10.4](#NCBK-10-4), [NCBK.2.8](#NCBK-2-8), [NERR.7](#NERR-7), [NFCT.1.4.6](#NFCT-1-4-6)

(NERR-6-1)=
[NERR.6.1] `-204` is **reserved**: it is never reused, and the native
Rete runtime does not produce it ([STYL.2.8.7]).

(NERR-6-2)=
[NERR.6.2] A `ds_fact_t *` held across pumps is valid only while its fact is
live ([NFCT.6.2]). An integrator that holds one **must** drop it at the fact's
`DS_EV_FACT_RETRACT`, or re-derive identity from the source state. A handle
used after its fact left working memory is undefined behaviour, which no status
reports; `DS_ERR_FACT_INVALID` is not that report ([IDAT.1.6]).

---

*see also:* [IDAT.1.6](#IDAT-1-6), [NFCT.6.2](#NFCT-6-2)

(NERR-7)=
## Storage / callback errors [NERR.7]

| Code | Meaning |
|---|---|
| `DS_ERR_STORAGE_UNAVAILABLE`  | a `call` fired with no call callback registered — **not** the cache verbs, which fall back to a volatile in-engine cache ([NSTG.2.1]) |
| `DS_ERR_STORAGE_QUERY_FAILED` | propagated verbatim from a callback that returned it |
| `DS_ERR_STORAGE_NOT_FOUND`    | integrator-driven from a storage-query callback; **not** a cache read — a `cached()` miss is engine-local and returns null, never this ([NSTG.2.2]) |

*see also:* [NSTG.2.1](#NSTG-2-1), [NSTG.2.2](#NSTG-2-2)

(NERR-7-1)=
[NERR.7.1] **`DS_ERR_STORAGE_UNAVAILABLE` is the most common pump-time error
during setup** — a rule's RHS issued a `call` with no call callback
registered. (The cache verbs are exempt: `cached()` reads the
engine's own map and `cache` / `cache_delete` fall back to a volatile in-engine
cache when no persistence hook is wired, [NSTG.2].) Register the callback
*before* loading rules that use the verb ([NCBK.12]).

---

*see also:* [NCBK.12](#NCBK-12), [NSTG.2](#NSTG-2)

(NERR-8)=
## DSC loader errors [NERR.8]

(NERR-8-1)=
[NERR.8.1] These surface from `ds_engine_load_dsc`. The detail names the failing
atom, the byte offset, and the violated RDSC rule.

| Code | Meaning |
|---|---|
| `DS_ERR_DSC_TRUNCATED`  | file too short; a declared atom length exceeds remaining bytes |
| `DS_ERR_DSC_BAD_MAGIC`  | the first atom is not a `DscHeader` ([RDSC.1.4]) |
| `DS_ERR_DSC_VERSION`    | the artefact is outside the runtime's version series |
| `DS_ERR_DSC_DECODE`     | an atom body fails protobuf decode |
| `DS_ERR_DSC_SEMANTIC`   | a decoded body violates a per-atom rule |
| `DS_ERR_DSC_DANGLING`   | a reference to an entity absent from the artefact |
| `DS_ERR_DSC_DECOMPRESS` | a body declared a compression codec other than `COMPRESSION_NONE`; the runtime carries no decompressor ([RDSC.4.5.1]) |
| `DS_ERR_DSC_CAPABILITY_ABSENT` | the artefact requires a capability this build was compiled without; the detail names the capability, as a value of `proto/capabilities.proto#Capability` ([RDSC.16.2.7]) |

*see also:* [RDSC.1.4](#RDSC-1-4), [RDSC.16.2.7](#RDSC-16-2-7), [RDSC.4.5.1](#RDSC-4-5-1)

(NERR-8-2)=
[NERR.8.2] **A failed load spends the engine** ([RDSC.9.8]), and whether
another load can succeed is the code's to say. A load that has begun reading the
artefact fails with one of these:

- **The artefact itself.** Every code in [NERR.8.1] and [RDSC.11.1];
  `DS_ERR_BND_INCOMPLETE`, for a `dialect_def_sha256` that is not 32 bytes
  ([RDSC.3.7]); and `DS_ERR_FN_NOT_FOUND`, for a call naming an op this runtime
  has no handler for where it stands ([RDSC.4a.9.3]). Every engine of this build
  refuses the same bytes the same way, so another load needs a corrected
  artefact, or, for `DS_ERR_DSC_CAPABILITY_ABSENT` and `DS_ERR_FN_NOT_FOUND`, a
  build that has what the artefact needs.
- **The engine's policy.** `DS_ERR_BND_DIALECT_MISMATCH`, when the admission
  policy does not admit one of the artefact's settings ([NLFC.10.2]). An engine
  with another policy can load the same bytes.
- **Neither.** `DS_ERR_OOM`.

Any further load takes an engine of its own.

---

*see also:* [NERR.8.1](#NERR-8-1), [NLFC.10.2](#NLFC-10-2), [RDSC.11.1](#RDSC-11-1), [RDSC.3.7](#RDSC-3-7), [RDSC.4a.9.3](#RDSC-4a-9-3), [RDSC.9.8](#RDSC-9-8)

(NERR-9)=
## AOT loader errors [NERR.9]

(NERR-9-1)=
[NERR.9.1] -550 to -553 are reserved and never reused ([IERR.2.8b]): a runtime
of this edition skips every `CompiledCode` atom and decodes none
([RDSC.4c.3]). -520 to -527 are reserved and never reused ([IERR.2.8a]).

The op check that *does* happen at load — a builtin call naming an op
with no registered handler — surfaces as `DS_ERR_FN_NOT_FOUND`,
censused at [NERR.10.1] and not duplicated here.

---

*see also:* [IERR.2.8a](#IERR-2-8a), [IERR.2.8b](#IERR-2-8b), [NERR.10.1](#NERR-10-1), [RDSC.4c.3](#RDSC-4c-3)

(NERR-10)=
## Native Rete & series-backend errors [NERR.10]

(NERR-10-1)=
[NERR.10.1] Native Rete loader / runtime codes:

| Code | Meaning |
|---|---|
| `DS_ERR_RETP_INVALID`, `DS_ERR_RETP_INDEX_OOB` | an `AlphaNode`, `BetaNode` or `TerminalNode` carrying `node_id` 0 or a repeated `node_id`, or a `left_parent_id` cycle; a node cross-reference not found ([RDSC.11.1]). A body that fails decode is `DS_ERR_DSC_DECODE` ([RDSC.11.4]) |
| `DS_ERR_FN_NOT_FOUND` | a call expression in the artefact names an op with no builtin; `ds_engine_load_dsc` refuses the artefact |
| `DS_ERR_BUDGET_EXCEEDED` | a bounded run reached its `max_fires` |

The realtime codes are [NERR.18]'s.

-600 is reserved and never reused ([STYL.2.8.7]): an artefact with no rule
network loads ([RDSC.4a.2]), and one with no `DscHeader` is refused as
[RDSC.11.1] states.

*see also:* [NERR.18](#NERR-18), [RDSC.11.1](#RDSC-11-1), [RDSC.11.4](#RDSC-11-4), [RDSC.4a.2](#RDSC-4a-2)

(NERR-10-2)=
[NERR.10.2] **Series-backend ABI.** Backend registration reports through its own
sub-block. **v1 accepts no integrator-supplied backend ([NSBK.2.3])**, so of these
only `DS_ERR_BACKEND_NOT_REGISTERED` reaches an integrator through a series
backend, and `DS_ERR_BACKEND_ABI_VERSION` also reaches one through the cache
callbacks ([NSTG.2.4]); the rest validate libds's own registration.

| Code | Value | Meaning |
|---|---|---|
| `DS_ERR_BACKEND_ABI_VERSION`     | -620 | `abi_version` mismatch: a series backend's vtable ([ISBK.1.7]) or the integrator's cache callbacks ([NSTG.2.4]) |
| `DS_ERR_BACKEND_BAD_MAGIC`       | -621 | a backend's `atom_field` names none of the seven backings ([ISBK.3.3]) |
| `DS_ERR_BACKEND_BAD_AGGS`        | -622 | `supported_aggs` exceeds the backing's static set ([ISBK.3.2]) |
| `DS_ERR_BACKEND_NOT_REGISTERED`  | -623 | a DSC series atom names a backing with no registered backend |

-624 and -625 are reserved and never reused ([STYL.2.8.7]): libds loads no
backend from a shared object.

The integer alone identifies the error, which is what [STYL.2.13.3] requires of
it: these values do not collide with the native-Rete loader codes above.

Backend-ABI codes come only from backend registration (NSBK), never from the
Rete loader.

---

*see also:* [ISBK.1.7](#ISBK-1-7), [ISBK.3.2](#ISBK-3-2), [ISBK.3.3](#ISBK-3-3), [NSBK.2.3](#NSBK-2-3), [NSTG.2.4](#NSTG-2-4)

(NERR-11)=
## Dialect / artefact-binding errors [NERR.11]

*checks:* `alloy`

(NERR-11-1)=
[NERR.11.1] Raised when artefacts that must agree do not (e.g. a `.dsc` and a
separately-built binding tuple disagree on hash or dialect). Rebuild all
artefacts from one consistent source.

| Code | Meaning |
|---|---|
| `DS_ERR_BND_DSC_MISMATCH`     | `dsc_sha256` disagrees between artefacts |
| `DS_ERR_BND_DIALECT_MISMATCH` | resolved settings or their hash disagree ([NDLC.4.5]), or the admission policy does not admit a setting ([NLFC.10.2]) |
| `DS_ERR_BND_INCOMPLETE`       | a required tuple field is missing / zero-length |

-704 is realtime's ([NERR.18]). -702 is reserved and never reused ([STYL.2.8.7]): an artefact carries no format
version to disagree on ([LDET.1.10]).

---

*see also:* [LDET.1.10](#LDET-1-10), [NDLC.4.5](#NDLC-4-5), [NERR.18](#NERR-18), [NLFC.10.2](#NLFC-10-2)

(NERR-12)=
## Declared-cap errors [NERR.12]

(NERR-12-1)=
[NERR.12.1] Raised when a declared cap would be exceeded: one of the caps
[LERR.1.5] names, of which the integration sets the cache bounds
([NSTG.2.6.1]). The other realtime codes are [NERR.18]'s.

| Code | Meaning |
|---|---|
| `DS_ERR_CONTRACT_BREACH` | a declared cap would be exceeded; the operation is refused and the engine stays usable |

---

*see also:* [LERR.1.5](#LERR-1-5), [NERR.18](#NERR-18), [NSTG.2.6.1](#NSTG-2-6-1)

(NERR-18)=
## Realtime codes [NERR.18]

The codes realtime raises ([NRTM.1.1]). A code is realtime's exactly when this
clause defines it. This clause is deferred, so none of these binds this
edition. Each keeps its number in `libds.h`, and this table is the one place it
is defined ([STYL.2.13.4]).

| Code | Meaning |
|---|---|
| `DS_ERR_WM_FULL` | assert rejected: `N_max` reached under a realtime contract ([NRTM.3.1]) |
| `DS_ERR_TOKEN_BUDGET` | a join fan-out cap was exceeded |
| `DS_ERR_RT_UNSAFE` / `DS_ERR_RT_LIVE` / `DS_ERR_RT_PRECOND` | RT mode with a required bound unset; an operation forbidden in LIVE mode; a go-live pre-condition unmet |
| `DS_ERR_BND_RT_CONFIG_MISMATCH` | `rt_config_sha256` disagrees between artefacts |
| `DS_ERR_CONTRACT_MISSING` | a `realtime` DSC has no `RealtimeContract` atom |
| `DS_ERR_CONTRACT_INVALID` | the `RealtimeContract` atom is malformed or its hash mismatches |
| `DS_ERR_RTCT_PROFILE_REFUSES_DSRT` | a profile binary was asked to write `.dsrt` |
| `DS_ERR_CONTRACT_WCET_HALT` | a pump exceeded `pump_wcet_ns`; returned by that pump, which halts the tier ([RTCT.7.3]). Later calls return `DS_ERR_ENGINE_HALTED`, but the few [NCBK.2.9] leaves valid |

---

*Deferred: not binding in this edition.*

*see also:* [NCBK.2.9](#NCBK-2-9), [NRTM.1.1](#NRTM-1-1), [NRTM.3.1](#NRTM-3-1), [RTCT.7.3](#RTCT-7-3)

(NERR-13)=
## Event-trace errors [NERR.13]

| Code | Meaning |
|---|---|
| `DS_ERR_FS_VERSION`           | an event-trace session header reports a `ds_version` outside the reader's `<major>.<minor>.` series ([LDET.1.10]) |
| `DS_ERR_FS_DIVERGENCE`           | replay: a re-derived compare atom (`RuleFireAnnotation`/`CallIssued`) differs byte-for-byte from the recorded atom at that `seq`, or is missing/extra/reordered — a determinism failure ([LFST.9.3.7]). Distinct from the `EngineDivergence` stream event. |
| `DS_ERR_FS_RECORDING_INCOMPLETE` (-729) | replay: the recording's first event has a `seq` other than `0` — its stream callback was attached after the engine's first input or sample, so the inputs before it are missing ([LTIM.2.8.5]) |
| `DS_ERR_FS_UNKNOWN_FACT_ID` (-730) | replay: a `FactRetract` names a `fact_id` that no earlier `FactAssert`, `FactEmit` or `ExternalAssert` left in working memory, or that an earlier `FactRetract` already named ([RFCS.7.3]) |

A replayed fact atom naming a schema the stream never announced, or one the
engine does not hold, is `DS_ERR_SCHEMA_UNKNOWN` ([RFCS.5.4], [NERR.5]).

`-721` to `-724` and `-726` are reserved and never reused ([STYL.2.8.7]). A recording's
header is refused as [RFCS.4.7] states.

See the determinism / event-trace doc (NDET) for the session header
(`ds_engine_get_session_header`).

---

*see also:* [LDET.1.10](#LDET-1-10), [LFST.9.3.7](#LFST-9-3-7), [LTIM.2.8.5](#LTIM-2-8-5), [NERR.5](#NERR-5), [RFCS.4.7](#RFCS-4-7), [RFCS.5.4](#RFCS-5-4), [RFCS.7.3](#RFCS-7-3)

(NERR-14)=
## Errors through callbacks [NERR.14]

(NERR-14-1)=
[NERR.14.1] Every registered callback returns `ds_result_t` ([NCBK.1.1]). A
non-OK status propagates to the caller of whatever public function fired the
callback, but the metric and log callbacks', which the engine drops
([NCBK.1.5]). For a callback fired
during a pump that is `ds_engine_pump`, which runs to exhaustion and reports
the **first** callback error ([NERR.15.1]).

*see also:* [NCBK.1.1](#NCBK-1-1), [NCBK.1.5](#NCBK-1-5), [NERR.15.1](#NERR-15-1)

(NERR-14-2)=
[NERR.14.2] **A detail string you return must stay valid until the outermost
public call that reports your status returns.** A pump that fires several
callbacks reports the first non-OK status ([NCBK.1.5]), so your detail can
reach the integrator only when the pump returns, after your callback has. Static
literals are simplest; if you build a message, allocate it per engine and free
it at teardown.

*see also:* [NCBK.1.5](#NCBK-1-5)

(NERR-14-3)=
[NERR.14.3] If you have no sensible status, return `DS_OK_R` and log internally.
Propagate only when the pump's caller needs to abort or retry.

---

(NERR-15)=
## Pump-time errors [NERR.15]

(NERR-15-1)=
[NERR.15.1] **A failure does not stop a pump.** The pump runs its agenda to
exhaustion ([NLFC.2.2]) whatever fails along the way, and returns the first
non-OK result from any of: a fact-event listener; the TTL sweep; a rule's RHS
action verb (e.g. an essential verb with no callback); a typed callback; the
stream sink. Two statuses take precedence over that first one: the pump's own
refusal of the call, and `DS_ERR_ENGINE_HALTED` when an `EngineError` halts the
tier, which stops the pump at the fault ([NCBK.2.9]).

*see also:* [NCBK.2.9](#NCBK-2-9), [NLFC.2.2](#NLFC-2-2)

(NERR-15-2)=
[NERR.15.2] After pump returns an error, engine state is whatever the pump
produced — there is **no rollback**. Subsequent pumps continue from there;
fixing the cause and pumping again resumes work. A halt is the exception: after
`DS_ERR_ENGINE_HALTED` nothing resumes, and the engine is only freed
([NCBK.2.9]).

---

*see also:* [NCBK.2.9](#NCBK-2-9)

(NERR-16)=
## Source locations [NERR.16]

(NERR-16-2)=
[NERR.16.2] Author-friendly DS source locations come from the artefact's `LineSpan`
atoms, which map Rete nodes to DS source spans. The runtime exposes that mapping
via `ds_engine_line_span_find` / `_at` and the DS-source views — see [NDBG]
and [RDSC].

---

(NERR-17)=
## Troubleshooting order [NERR.17]

(NERR-17-1)=
[NERR.17.1] The order you typically meet errors during setup:

1. **`DS_ERR_INVAL` from `ds_engine_new`** — argument
   validation; read the detail.
2. **`DS_ERR_DSC_*` / `DS_ERR_RETP_*` from
   `ds_engine_load_dsc`** — a malformed or wrong-target artefact; the detail
   names the failing atom and rule. Recompile.
3. **`DS_ERR_STORAGE_UNAVAILABLE` from `ds_engine_pump`** — a rule fired an
   action verb with no registered callback; the detail names the verb. Register
   it before loading rules that use it.
4. **`DS_ERR_BACKEND_NOT_REGISTERED` from `ds_engine_load_dsc`** — the artefact
   names a series atom that no backend in this libds serves ([NSBK.2]). libds registers every backend itself, so there is
   nothing to register: recompile with this release's compiler.
5. **Your own callback's return code** — you wrote it; the detail and code are
   what you put there.

*see also:* [NSBK.2](#NSBK-2)

(NERR-17-2)=
[NERR.17.2] Errors at `ds_engine_free` usually signal a misuse pattern (e.g.
double-free of a fact pointer obtained from a callback); they are rare, and
typically fatal — log and abort.

