The error record
A failure is one reason and one provenance; its text and process code are projections, not independent facts, and a program reads only the projection. This supersedes in part status-is-the-outcome: the run’s status remains an outcome projection, and the failure’s code is derived from its reason too.
Why
- A stored status duplicates the reason’s Unix encoding and requires an
agreement check on re-raise. Two isomorphic sums, runtime
Statusand dataReason, require conversions without adding information. - A stored message can contradict the reason. Only raised text is data; spawn detail belongs in the reason’s payload, not in prose.
- Fresh failure and re-raising have different arguments. Giving both to
failwould require type-directed overloading; two names state two rules. - Independently stamped names and spans can name different frames. Partial
sites make worker observers relocate one failure at
done,pollandawaitinstead of observing it. - A reason is Rust’s closed taxonomy of causes. A program that branches on it binds itself to that taxonomy, and the checker would carry its whole type. A program needs a wording and a status; the reason serves the wire, logs and hosts.
- Unwind notes encoded in hint strings suppress one another and cannot count discarded bytes. Facts about an unwinding are not advice about a failure.
- A frame name read as the failed program words an external run from invisible code with the wrong subject and misses its exit hints. The program is a coordinate of the process failure, not of provenance.
The record and the two rules
Reason = process [program: String, failure: Failure]
| timed-out | cancelled | raised Claim
| denied Denial | io IoFailure | invalid InvalidFailure
| evaluation EvalFailure | state StateFailure | compile CompileFailure
| launch LaunchFailure | protocol ProtocolFailure | host HostFailure
| invariant InvariantFailure
Claim = [message: String, status: 1..=255]
Failure = exited Int | signaled Int | not-found
| not-runnable [found: String, why: Unrunnable]
Unrunnable = permission-denied | directory | not-executable
| missing-interpreter (Option String) | io IoCause
ErrorFact = [frame: String, reason: Reason, site: CallSite] -- Rust, Datum
ErrorRecord = [frame: String, message: String, status: Int,
site: [script: String, line: Int, col: Int]] -- Datum + Typed
ErrorFact::record : ErrorFact → ErrorRecord
message ↦ Reason::describe, status ↦ FailureCode::failure_code
fail : ∀ε α. String → F^ε α
raise : ∀ε α. ErrorRecord → F^ε α
⟨ fail m | κ ⟩ → ⟨ ↯(raised [m, 1], prov κ) | κ ⟩
⟨ raise e | κ ⟩ → ⟨ ↯(reason w, at (frame w, site w)) | κ ⟩ e witnesses w
⟨ raise e | κ ⟩ → ⟨ ↯(raised [message e, status e], at (frame e, site e)) | κ ⟩
e hand-builtReasonis the one sum, a Rust-side fact. It lives on runtimeErrorand inErrorFact, the wire’s and the logs’ failure (core/src/fact/error.rs). It isDatumbut neverTyped: it does not reach the checker. Process-layer failures convert once, keeping the command head as dispatched asprogram; not-runnable detail includes the path found (else the program), with typedIoCauseretaining OS evidence. Operational failures retain closed subjects and causes; only explicitly authored text isRaised. Large reason payloads are boxed so runtimeErrorstays below 128 bytes.Error::new(reason: Reason)accepts no implicit string conversion.- A program reads the projection.
ErrorRecordisErrorFact::record(); itsstatusis aNonZeroU8, so it is a failure code by construction.messageandstatusare derived from the reason and never stored beside it: no type holds both aReasonand amessage.Done = Ending<(), ErrorRecord, CancelCause>carries the record to hosts and done events. Raisedis the program’s claim.fail mraisesClaim { m, 1 }; a hand-built record raises its ownClaimwith its own frame and site. Its wording is its message and its code is its status.- One code table is
FailureCode for Reason.processdelegates toFailure:exited nclamps throughfailure_byte;signaled sgives 128+s;not-found127;not-runnable126.timed-out124;cancelled143;raisedits claim’s status (1 forfail); operational families andinvariant1. A worker’s own stop becomestimed-outorcancelledthroughReason::stopped; errors, facts and records delegate to the reason or, for a record, its stored status.CancelCausekeeps its own codes (aborted 131, …). External rawi32survives for wording and hints until code projection. Panic 101 belongs to the ending, not the reason. Choosing a script code is top-levelexit n, notfail. The table is the shell tradition’s, not an endorsement: the golden rule may revisit it. Reason::describeis the one wording of a reason; the record’smessageis that wording. There is nodescribebuiltin:$e[message]is it. Process wording takesprogramas its subject; provenance never enters it.ErrorandErrorFactmethods delegate to it, as do diagnostics, audit failure text and worker notices. Compact(exit status N)appears only for timed-out/cancelled workers. A matchingfound == programgets the short not-runnable wording; Windows Ctrl-C termination retains its specific wording.- A caught record witnesses its fact. To the language the record is an
ordinary map. Its runtime representation is
Map’sWitnessedvariant (core/src/shell/runtime/map.rs), which holds theErrorFactit projects;Map::witnessedis the only constructor, so the map is exactlyfact.record(). Reads, equality, printing and patterns cannot tell it from a built map.Value::failureconstructs the witnessed runtime records intry’s handler argument,polland the audit report’s`erroutcome. Done events and worker listings instead carry plainErrorRecorddata throughFOValue; raising those records makes a claim. raiseof a witnessed map re-raises the exact reason, at the fact’s frame and site, with no validation: the reason was witnessed. Any change (insert, spread) builds a new map without the witness, and so does crossing a seam as data (FOValue, JSON, the wire); a changed record is a hand-built record. A worker’s own failure crosses as anErrorFact, not as a value.raiseof a hand-built record validates the claim. The closed type rejects extra fields and wrong field types at check time; data must decode toErrorRecord. Status 0 isInvalidCause::ZeroStatus(usereturn); above 255 is a decode refusal. Otherwise the record is raised as given, including hand-built provenance:[frame: f, message: m, status: 3, site: s]is reported as that claim and yields code 3. An opaque error type was rejected: records crosstry,poll,doneand the wire as ordinary data.
One provenance from the continuation
prov κ is the innermost visible operation frame, the redex’s own included.
Visibility has one definition: the span lies in a session source.
framenames the reporting frame, not necessarily a command, and is pure provenance: shown with the site, never the subject of process wording. An evaluator refusal names an operation such asindex; visiblefailnamesfailat that call. The baked prelude is invisible, solast []names and sites the user’slast._remains module privacy, not a provenance rule.Break::locateclaims an unset provenance once, with both name and span.Provis live name/span (caret rendering) or resolved name/CallSite(coordinate rendering). Dispatch claims command/native failures; evaluator operations claim their own refusals, without fallbackExec/Appstamps.- One total register tracks the current visible continuation frame and is
saved/restored with it. The field is private to
Audit:enter_sitereturns an opaqueDisplacedSitethat onlyrestore_siteconsumes, so every write is bracketed. A source base installs its root span; a hook base installs its origin at 1:1; workers inherit the register at spawn. A failure no inner frame claims is sited at its run’s start,script:1:1; so is a result refused at the data boundary, fromRunReport::Ran.base. - Record minting reads error provenance, else the register. Audit observation
sites use the same total register. With no listeners,
audit_startreturnsNonewithout the observation work. - A child shell forks the source registry; the prefix it inherited stays shared. An ending leaving a worker or pipeline stage resolves every live provenance past that prefix, since the parent may register another file at the same id.
- Stops carry the same provenance. Worker stop conversion preserves it, and
the worker completes any unlocated error before publication.
done,pollandtryaroundawaittherefore receive identical worker records.
Report facts are not the value
- The reason determines ordered intrinsic advice, including signal advice and
operational remedies; the renderer also looks up the session exit-hints entry
for
exited. These are recomputed at each render and so survive theraiseof a witnessed record. Everything stored belongs to one unwinding: stored hints, context prefixes, witnesses, compile rejections and unwind facts are report-only. - Hints accumulate in attachment order and none overrides another. A denial’s
intrinsic remedy precedes stored hints; other reasons show stored hints,
report-context advice, then intrinsic and exit-table advice. Contextual advice
does not survive without the report context (
docs/SPEC.md§13.1). - Context applies to every reason without rewriting it.
Unwound { abandoned_tail: bool, discarded: u32 }records abandoned written steps and sums capture bytes saturatingly; escapes carry no such facts. - One renderer composes the hints, the counted discard note, then the abandoned-tail note. The latter is omitted for spawn failures or when a hint precedes it.
- A handler’s re-raise preserves the record and keeps every hint the record
determines, including the session exit-hints lookup. It drops stored
hints, context and unwind facts from the first unwinding. A resolved site
renders without a caret.
awaitpropagates the live error: no handler intervened, so its report facts remain. - No output bytes, arbitrary payload map or failure aggregation enter the
record. Audit keeps forensic bytes; domain outcomes are values. Refusals use
typed causes, not
raisedplus a frame name. A loaded source’scompilesummary is intrinsic; its rich source-labelled rejection is report-only.
Amended (261107). Hints accumulate and none overrides another. The original text let situational hints override reason hints; that hid true advice (a sandbox denial hid the signal advice and the exit-hints entry). Path-as-text is a stored hint, written by the evaluator when a grant refuses a path head, not a reason hint. The error is one type in every layer (
Error,core/src/error.rs):reasonandprovare its only public fields, each report fact is private with one writer (with_hint,with_context,with_witness,with_rejection),Error::newis the one constructor, and anErrorenters control flow only throughFrom<Error> for Break.
Amended (261110). A program no longer reads
reason.Reasonstays a typed Rust-side fact, carried by the wire and logs asErrorFact; the language readsErrorRecord = [frame, message, status, site], its projection. Thedescribebuiltin is gone ($e[message]).raiseof a caught record re-raises its exact reason through the map’s witness; a hand-built record is the program’sClaim. The one-sum, one-provenance core above is unchanged.
Amended (261113). By runtime values are value closures, a caught failure is plain record data with no witness, and
raiseof any record is the program’sClaim, keeping frame, message, status and site, without restoring the typed cause or the hints it determined.
A refused block is one fact
A block the runtime vets and the checker refuses is InvalidCause::IllTyped:
its role, and every diagnostic’s stable code and rendered message.
IllTyped = [role: BlockRole, diagnostics: List TypeDiagnostic] -- non-empty
BlockRole = handler String | catch-all | hook String | binding String
TypeDiagnostic = [code: String, message: String] -- "T0057", rendered- The vetted blocks are a persistent or
withinhandler, thewithincatch-all, a hook registration and an rcbindings:entry. The wording isthe `git` handler does not typecheck: T0057 <message>; …(IllTyped::describe,core/src/fact/error/invalid.rs). - The checker’s runtime entry points (handler-arm checking,
catch_all_stands_in,binding_value_scheme,core/src/typecheck.rs) return every error from close, not the first.TypeError::diagnosticis the one projection toTypeDiagnostic, andill_typed(core/src/shell/runtime/coerce.rs) the one builder. Handlers keep their caret throughBreak::locate.
Hosts and transport
- The wire ending is
Ending<FOValue, ErrorFact, CancelCause>(protocol::Ending) and carries the fact, typed reason included, through its strictDatumencoding. Exarch’s shell report reads that ending.Donecarries theErrorRecord, andDisplay::Doneinrecord.jsonluses its encoding. The protocol version changes; there is no compatibility for old records, envelopes or scripts. Report::StaticandFaultedkeep their nonzero host status. A desk refusal has no status field: it is anErrorthat crosses either carrier as aWireError(reason, optional reportcontext, ordered storedhints).WireError::to_errorpreserves the reason rather than reclassifying rendered text asRaised; provenance, witnesses, rejections and unwind facts stay out of this envelope.- Boot answers
settledsettings orcapabilities-refuseddiagnostics, rendered engine-side so compile reports survive. The host chooses exit 2 for capability rejection; rc failures remain error endings. exited nis an ending (the computation ranexit n) and, separately, a processFailure; the reason isprocess [...], so the two never share a sum.
See failure, endings,
capture, diagnostics and
docs/SPEC.md §8.5–§8.6, §13.