Error handling
Platform spec node
Error handling
Spec standingStandard
No architecture decision records under adr/ for this feature yet. Standard features must
publish at least one ADR or keep a ## Decisions summary on the hub.
- Contracts Structural contract declarations, conformance lists, and embedding. Distinct from compiler Mod SDK contracts and from runtime requires/ensures (not in v0.1 grammar).
- Error handling Representing and propagating failures (`Result`, `try`, unwinding policy). Runtime lowering shares the ABI error envelope described in Execution.
- Testing The language-level test harness, discovery, and assertions users rely on. Corelib testing helpers extend but do not redefine these semantics.
0 revisions (git unavailable at build; counts may be empty)
No commits recorded for this path.
| Section id | Required | Found |
|---|---|---|
scope | yes | yes |
features | yes | yes |
Full tree: run pnpm verify:platform-spec-layout (writes src/generated/platform-spec-layout-report.json).
Error propagation flow
Section titled “Error propagation flow”flowchart LR expr[expr with Result enum] tryOp[postfix ? operator] ok[unwrap success value] err[return / translate Err] expr --> tryOp tryOp -->|Ok variant| ok tryOp -->|Err variant| err ffi[FFI boundary] --> envelope[interop error envelope] err -.->|no silent throw| ffi
Normative specification
Section titled “Normative specification”Defines how recoverable failures are represented and propagated in user code. ABI envelopes and unwind across FFI are in interop and execution chapters.
Result, Option<T>, and enums
Section titled “Result, Option<T>, and enums”- Recoverable errors should use
Core.Results.Result<TValue, TError>from corelib when the project links Std (prelude exposesCore.Results). - In App projects with implicit Std, the assembly module path is
Std::Core::Results(source may writeStd.Core.Results.Result<i32, string>); inside corelib shards the path remainsCore.Results.Result<_, _>. - There is no built-in
Result<T,E>type alias in v0.1 grammar; use the corelib generic enum with explicit type arguments. - Projects must not define a second bare
enum Resultin the same scope as Std; use the corelib type or a distinct name. - Absence of value (not failure) must use
Option<T>, notnullor sentinel pointers (must align with Types).
try postfix operator
Section titled “try postfix operator”- Postfix
expr?(TryOperator) must apply only where the surrounding function or lambda declares a compatible error propagation target. - Operand type must be a
Result-shaped enum (typicallyCore.Results.Result<_, _>withOk/Errorvariants); otherwise invalid try target (E12xx family in reference compiler). - Successful path must unwrap the success payload type into the expression context; failure path must return or translate to the enclosing error type.
- Lowering must desugar
?using the resolved scrutinee enum (variant names from that enum), not hard-coded identifier strings. - Analyze, compile (
run/build), and LSP must share the same typed-HIR spine: resolve, normalize (including?desugar), re-resolve, then type-check.
Static rules
Section titled “Static rules”trymust not appear on non-enum/non-result expressions.- Panic or abort semantics are not language keywords in v0.1; unrecoverable failures use host/runtime policies.
Dynamic semantics
Section titled “Dynamic semantics”- Error propagation must not implicitly allocate; lowering rewrites
?to branch sequences. - FFI boundaries must map errors per Interop contracts — no silent cross-language exceptions unless documented.
Diagnostics
Section titled “Diagnostics”InvalidTryTarget and type mismatch on unwrap paths. Registry: Diagnostic code registry.
Conformance
Section titled “Conformance”Programs using ? must compile only when propagation types align; reference tests cover try lowering.
Decisions
Section titled “Decisions”- D-LM-ERR-001 — Enum-first errors: Language law prefers explicit sum types over magic result types.
- D-LM-ERR-002 — No exceptions keyword: Cross-language unwinding is interop-scoped, not a Beskid
throwstatement in v0.1. - D-LM-ERR-003 —
OptionvsResult:Option<T>models missing data;Result-shaped enums model failures—do not conflate them. - D-LM-ERR-004 — Postfix
?only: Error propagation usesexpr?; there is notrystatement form in v0.1. - D-LM-ERR-005 — Corelib
Result: With Std linked, canonical recoverable-result type isCore.Results.Result<TValue, TError>;?lowering and type-check use that enum’s resolvedOkvariant.
Platform view
Section titled “Platform view”Representing and propagating failures (Result, try, unwinding policy). Runtime lowering shares the ABI error envelope described in Execution.