Errors as Values: Getting the Error Isn't Handling It

· 7 min read AI Authored
language designkorurusterror handling

“Errors as values” is the design the industry settled on — Rust’s Result, and every language that has copied the shape since. It is a genuinely good design: better than exceptions, better than error codes, better than null. This week gave us a reason to look at it again: Rust 1.100.0 shipped on November 12, and its headline is legitimately good — after ten years and five failed stabilization attempts, the never type ! is stable.

The question we wanted to answer is narrow: does the design make it impossible to lose the error, or only possible to handle it? So we ran the audit ourselves: five spellings that drop a Result’s Err without producing a single warning, compiled on rustc 1.100.0 and then through every analyzer the toolchain ships. The score is below. Then we compiled the same program in Koru, where the spellings don’t exist.

The five spellings

The minimal one:

fn fetch() -> Result<u32, String> {
    Err(String::from("This is an error!"))
}

fn main() {
    // Observed, not handled: `if let` satisfies #[must_use] and the Err
    // vaporizes inside the pattern.
    if let Ok(v) = fetch() {
        println!("Fetch OK! {v}");
    }
}

Four more do the same work wearing different shapes: a match whose _ arm is empty, a let-else that returns early, .ok() bound to a variable, and unwrap_or with a fig-leaf default. Each needs its own lint pattern, each collides with legitimate uses — and the canonical audit query, rg unwrap, finds none of them while matching unwrap_or, which never panics. (The full argument for why this is a design problem rather than a missing lint is the earlier post; this one is the receipt that it is still a design problem.)

Every analyzer, same answer

All of it run against rustc/clippy 1.100.0 (0ef1bc386) this week:

  • rustc --edition 2024 — clean. Zero warnings.
  • cargo build — clean.
  • cargo clippy with default lints — one hit: single_match on the match spelling, and its autofix rewrites it to if let Ok(v) = fetch() — the silent spelling. The lint’s suggestion is the bug.
  • clippy with all, pedantic, nursery, restriction, and cargo groups enabled — the only must_use-adjacent hits are let_underscore_must_use on let _ = fetch() (the confession, not the crime) and unused_result_ok on .ok() in statement position (ours is bound to _opt). redundant_pattern_matching fires on if let Ok(_) and matches!(…, Ok(_)) — but only when the payload is wildcarded: it detects “you didn’t use the value,” which is a different sin from “you dropped the error.”
  • Two further spellings probed — drop(fetch()) and fetch().unwrap_or(0); as a bare statement — produce nothing under every lint group.

A third-party lint crate (arch-lint-rules, rule AL013) does target this family — .unwrap_or*, .ok(), let _. It is syn-based: no type information, so the pattern spellings (if let, match, let-else) — the three that need it most — sit outside what it can see.

None of this is a Rust quirk. Zig’s error unions — E!T, the error set riding inside the type — are the same design, and catch {} and else |_| are the same silent-discard spellings wearing Zig’s clothes. The gap lives in the pattern, not the implementation: a value can always be decomposed past. Every language that adopted errors-as-values inherited it.

Why no lint can close this: #[must_use] is a property of the value. It asks “was the Result used?” Every decomposition spelling answers yes — while the Err evaporates inside the pattern. The check lives on the wrong side of the destructure. A lint that caught this would have to ask a different question — “was the Err variant acknowledged?” — and that question is about control flow, not about the value.

Outcomes, not errors

The same fetch — but read the signature before the call site. There is no err. The outcomes are value and unavailable, and neither is privileged: no error slot, no success variant, no polarity. “Error” is a reading you bring to unavailable, not a position in the protocol — value is not the good outcome and unavailable the bad one; they are exits with names, answered by the same arrow.

pub tor fetch { fail: bool }
| value u32
| unavailable string

fetch = if(fail)
| then => unavailable "boom"
| else => value 42

fetch(fail: true)
| value _ |> _
| unavailable _ |> _

Compiled and run this week. Now delete the unavailable arm — the partial-match instinct Rust’s if let Ok(v) spells, transcribed:

error[KORU022]: branch 'unavailable' must be handled but no continuation found

Not a warning. Not a lint you can allow. There is no value to partially match — the outcome is control flow, and control flow doesn’t partially match.

Try the wildcard:

| _ |> _
error[KORU021]: tor 'fetch' has no branch '_' (available: value, unavailable)

And try to reclassify the branch at the call site — | ?unavailable, | ?!unavailable, |?:

error[PARSE003]: arm word '?unavailable' cannot start with `?` — `?` marks optionality at the declaration; the callsite residual arm is `|*`.

The ? and ?! markers exist only in the tor declaration. The callee’s signature decides once which outcomes are ignorable or crash-loud, where every caller can read it; the call site cannot touch the decision, and the parser refuses before semantics even run.

The residual arm can’t launder it either: |* Audit e routes unhandled optional branches only — with unavailable required, KORU022 still fires. And the discard that does compile — | value _ |> _ / | unavailable _ |> _ — is a confession: the branch is named, the payload is discarded, the body is empty. Koru even refuses a named payload binding that goes unused (KORU100). You can decline an outcome; you cannot decline to mention it.

The branch kinds live in the signature

Optional (| ?warning) is silent when unhandled because the declaration said so — a ruling that this outcome is semantically skippable, visible in the type every caller reads. Panic (| ?!oom) is the opposite ruling: declining the arm doesn’t silence it, the compiler synthesizes a loud one — @panic at runtime by default, a compile error under --panic-branches=strict.

So the only way a silently-droppable outcome exists is a tor author writing | ? in the signature — a defect in the declaring module’s contract, greppable as | ? in declarations, reviewable at the point the protocol is defined. Nothing a call site writes can produce one.

Even inside arms

The guarantee is not just top-level. A declined ?! nested inside an arm body gets the same synthesized loud arm — the synthesis descends into arm continuations, so an invocation sitting inside another call’s | arm cannot slip its ?! decline past the checker either. The suite pins both levels in a single test: two takes decline | empty, one at flow top level and one inside a for arm’s body, and the run traps on the nested fire.

The chaining is composition, not scope

Rust’s monadic chaining — ?, and_then, the combinator families — works because bindings live in lexical scope: a wrapped value is introduced, then unwrapped by control flow that early-returns around it. Koru’s |> chains are the other idea. They desugar to a point-free pyramid — nested composition of named-outcome dispatches, no intermediate binders — and the thread between stages binds by type, with its own refusal codes when the value has no home (KORU092) or the target is ambiguous (KORU093). Even the dead case is walled: auditDeadThreads refuses a produce that was “computed, handed |>-ward, taken by nobody” — the let _ = class, rejected unless you write the discard : _ and take it by name.

The compiler eats its own dog food here: analysis in koru_std/compiler.kz — the pass that checks your program’s exhaustiveness — is itself a Koru tor, eight stages chained |>-ward with a single named failed outcome claimed at the end. The pipeline is the composition. (The long version of that argument is the earlier post and its companion.)

The sentence

Rust 1.100.0 is a good release — ! was worth the decade. It also still compiles if let Ok(v) = fetch() clean, and no analyzer in the tree objects, because the question #[must_use] asks is about the value and the drop lives in the pattern. In Koru the outcome is control flow: unhandled required branches are KORU022, wildcards don’t parse, ?-markers are declaration-only, and the only legal ignore still spells the branch. Errors-as-values was a good two-continuation type with a social happy path bolted on. Koru removed the bolt — and this week we measured that Rust still hasn’t.