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.
The ds_result_t shape [NERR.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, RARC.3.3.3, NERR.1.2, NERR.1.3
[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] 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.
Detail-string lifetime [NERR.2]#
[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
[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] 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
Code ranges [NERR.3]#
[NERR.3.1] Codes are grouped by numeric range; each range maps to a subsystem and a recovery disposition.
Range |
Category |
Disposition |
|---|---|---|
|
OK |
continue |
|
Generic |
check args / state, fix and retry |
|
Input |
fix the input: the fact, the text or the encoded body that does not fit |
|
Runtime |
check fact / activation state |
|
Storage / callbacks |
check integrator-side wiring |
|
Artefact load |
rebuild the |
|
Native Rete / realtime |
check the rule network / RT config |
|
Series-backend ABI |
at |
|
Dialect / artefact binding |
rebuild artefacts from one consistent source; |
|
Realtime contract |
see NRTM |
|
Event-trace |
trace session header + replay refusals + unknown inject-band atom; |
This table and the registers of [IERR.2] are one register in two places, and
the second is authoritative: [IERR.2.8a] and [IERR.2.8b] for -500..-599,
[IERR.2.8.1] beyond it. Compiler diagnostics appear in
neither: they are not ds_status_t values ([RTCT.9.1]).
A category is the project's name for its family. A binding that exposes the families as types must name each type for its category, in the binding language's idiom, and must not name a family for what another category holds.
checks: alloy×7 — see also: IERR.2, IERR.2.8.1, IERR.2.8a, IERR.2.8b, NERR.10.2, NERR.11.1, NERR.13, NERR.8.1, NERR.9.1, RTCT.9.1
[NERR.3.2] -300..-399 are permanently reserved and are never produced or
reused ([STYL.2.8.7]). -205 is not in that band and is live: it is
DS_ERR_TIME_RANGE ([NERR.6]).
checks: alloy×3 — see also: NERR.6
Generic errors (-1..-99) [NERR.4]#
Code |
Meaning |
|---|---|
|
NULL pointer to a non-optional argument; invalid enum; out-of-range integer |
|
allocation failed inside libds; its detail may be NULL ([NERR.2.3]) |
|
required lookup miss (e.g. |
|
rejected by current engine state (e.g. |
|
a bounded queue / counter would overflow (internal boundaries) |
|
an operation unavailable in this build (e.g. |
|
invariant violation inside libds — a bug; file an issue with the detail |
|
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]) |
|
an |
see also: NCBK.1.5, NCBK.2.9, NERR.2.3, NFCT.1.1, NSTG.3.3, RARC.13.16, RARC.13.17, RDSC.9.8
[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.
Input errors (-100..-199) [NERR.5]#
Code |
Meaning |
|---|---|
|
a DSC atom body, or |
|
an action referenced a schema that isn't registered; or a replayed |
|
a referenced slot is not on the schema |
|
a slot value's |
-102 and -105 to -108 are reserved and never reused ([IERR.2.4]).
ratified — see also: IERR.2.4, LGRA.5.8.10, LGRA.5.8.7, LGRA.5.8.9, RFCS.5.4
Runtime errors (-200..-299) [NERR.6]#
Code |
Meaning |
|---|---|
|
|
|
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 |
|
a |
|
a NaN |
|
a host call that would put a non-finite |
|
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 ( |
|
|
|
|
|
a |
|
text the host hands the engine is not well-formed UTF-8: a |
-201 and -203 are reserved and never reused ([IERR.2.5]).
see also: NFCT.3.2, IDAT.1.6, IERR.2.5, LDET.3.2.7, LEXP.4.2, LGRA.5.8.10, LGRA.5.8.6, LSER.19.8, LSER.9.1.1, LSTR.8.5, LTIM.1.1.5, NCBK.1.5, NCBK.10.4, NCBK.2.8, NERR.7
[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] 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]).
Storage / callback errors (-400..-499) [NERR.7]#
Code |
Meaning |
|---|---|
|
a |
|
propagated verbatim from a callback that returned it |
|
integrator-driven from a storage-query callback; not a cache read — a |
[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]).
DSC loader errors (-500..-549) [NERR.8]#
[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 |
|---|---|
|
file too short; a declared atom length exceeds remaining bytes |
|
the first atom is not a |
|
the artefact is outside the runtime's version series |
|
an atom body fails protobuf decode |
|
a decoded body violates a per-atom rule |
|
a reference to an entity absent from the artefact |
|
a body declared a compression codec other than |
|
the artefact requires a capability this build was compiled without; the detail names the capability, as a value of |
see also: RDSC.1.4, RDSC.16.2.7, RDSC.4.5.1
[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 adialect_def_sha256that is not 32 bytes ([RDSC.3.7]); andDS_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, forDS_ERR_DSC_CAPABILITY_ABSENTandDS_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, NLFC.10.2, RDSC.11.1, RDSC.3.7, RDSC.4a.9.3, RDSC.9.8
AOT loader errors (-550..-599) [NERR.9]#
[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.
Native Rete & series-backend errors (-600..-625) [NERR.10]#
[NERR.10.1] Native Rete loader / runtime codes:
Code |
Meaning |
|---|---|
|
an |
|
a call expression in the artefact names an op with no builtin; |
|
a bounded run reached its |
The band's 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, RDSC.11.1, RDSC.11.4, RDSC.4a.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 |
|---|---|---|
|
-620 |
|
|
-621 |
a backend's |
|
-622 |
|
|
-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.
checks: alloy×11 — see also: ISBK.1.7, ISBK.3.2, ISBK.3.3, NSBK.2.3, NSTG.2.4
Dialect / artefact-binding errors (-700..-704) [NERR.11]#
checks: alloy
[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 |
|---|---|
|
|
|
resolved settings or their hash disagree ([NDLC.4.5]), or the admission policy does not admit a setting ([NLFC.10.2]) |
|
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]).
Declared-cap errors (-710) [NERR.12]#
[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 rest of the band is realtime's ([NERR.18]).
Code |
Meaning |
|---|---|
|
a declared cap would be exceeded; the operation is refused and the engine stays usable |
see also: LERR.1.5, NERR.18, NSTG.2.6.1
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 |
|---|---|
|
assert rejected: |
|
a join fan-out cap was exceeded |
|
RT mode with a required bound unset; an operation forbidden in LIVE mode; a go-live pre-condition unmet |
|
|
|
a |
|
the |
|
a profile binary was asked to write |
|
a pump exceeded |
Deferred: not binding in this edition.
Event-trace errors (-720..-730) [NERR.13]#
Code |
Meaning |
|---|---|
|
an event-trace session header reports a |
|
an |
|
replay: a re-derived compare atom ( |
|
replay: the recording's first event has a |
|
replay: a |
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 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, LFST.9.3.7, LTIM.2.8.5, NERR.5, RFCS.18.8, RFCS.4.7, RFCS.5.4, RFCS.7.3
Errors through callbacks [NERR.14]#
[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.5, NERR.15.1
[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
[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.
Pump-time errors [NERR.15]#
[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]).
[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
Source locations [NERR.16]#
[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].
Troubleshooting order [NERR.17]#
[NERR.17.1] The order you typically meet errors during setup:
DS_ERR_INVALfromds_engine_new— argument validation; read the detail.DS_ERR_DSC_*/DS_ERR_RETP_*fromds_engine_load_dsc— a malformed or wrong-target artefact; the detail names the failing atom and rule. Recompile.DS_ERR_STORAGE_UNAVAILABLEfromds_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.DS_ERR_BACKEND_NOT_REGISTEREDfromds_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.Your own callback's return code — you wrote it; the detail and code are what you put there.
see also: NSBK.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.