Skip to content

Failure And Propagation

Chris Michael edited this page Sep 2, 2026 · 3 revisions

Pudu

Failure And Propagation

fn load(path: Str) -> Result[Str, Str] {
  let text = readFile(path) ?
  Ok(text)
}

Status: Result, Option, exhaustive matching, postfix ?, typed early return, and panic execute in the interpreter. Pudu does not use exceptions for expected failure.

Result and Option

type Result[T, E] = Ok(T) | Err(E)
type Option[T] = Some(T) | None

Operations that can fail recoverably return a carrier. Standard-library effects generally use Result and preserve the operating-system message as text.

Postfix ?

? reads its carrier from the enclosing function return type.

fn first(value: Option[Int]) -> Option[Int] {
  let held = value ?
  Some(held)
}

In a Result function, Err(error)? returns the same Err(error) and requires the exact declared failure type. Failure conversion is not implemented. In an Option function, None? returns None. A target with the wrong carrier is a type error; ? does not catch panic.

W3003 identifies a match that merely rebuilds the same failure carrier and can be written with ?. A branch that transforms the error or changes the carrier is a real decision and is not warned.

Choosing among the forms

Need Form
Forward the same failure ?
Bind one success and exit otherwise let PATTERN = value else { ... }
Run one success branch with optional fallback if let PATTERN = value { ... }
Transform or recover from several cases match

Panic

panic represents a violated invariant, not a recoverable domain outcome. Compile-time effect restrictions, runtime diagnostics, and ordinary failure carriers remain separate.

Related

Clone this wiki locally