Skip to content
Beskid The Beskid Book

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

09.1 Errors and Result

Represent recoverable failures with enums and propagate them with try/? — not exceptions.

Errors and Result

Beskid does not resurrect C# exceptions for breakfast. Recoverable failures are values you pattern-match, propagate with ?, and translate at boundaries.

Normative rules: Error handling.

  • Model errors as enum variants (Ok / Err or domain-specific shapes).
  • Option<T> is the optional type—there is no optional keyword.
  • Postfix ? on a Result-like expression: success unwraps; Err returns or translates from the current function.
flowchart LR
  expr[Expression with Result type]
  q[Postfix ?]
  ok[Continue with success value]
  err[Return Err from enclosing callable]
  expr --> q
  q -->|Ok| ok
  q -->|Err| err

At foreign boundaries, errors become ABI envelopes—no silent throw across the wall. See Interop contracts and Error and unwind semantics.

PracticeWhy
Named error enums per domainCallers can handle variants without string archaeology
? for happy-path plumbingLess nesting than manual match everywhere
Translate at module boundariesKeep internal Err types out of public APIs

Type and flow mistakes surface as compiler diagnostics in the E16xx band (contract-related) and analysis rules tied to semantic pipeline.

Contracts in source