Manuscript Documentation
v2026.12.0

Error handling#

Use Result for an expected failure with a cause, Optional for a missing value, and a fault for a broken programming assumption.

ConceptWhat you will learn
Expected failures with ResultReturn success or domain errors as ordinary values.
Error propagation with ?Forward compatible errors without hiding faults or cancellation.
Programming faultsCheck invariants and understand task failure after cleanup.

Choosing a failure in the standard library#

The standard library picks the failure by its cause. Your own functions can follow the same rule.

CauseResultExamples
A value is missingnull from a T?first() on an empty list, Map.get(key), parse_int on text that is not a number
The caller passes a bad value: a size, count, radix, budget or other argumentAn Error of kind EINVAL when the function already returns Error, else null when it already returns an optionalrate_limiter with a nonpositive rate, to_string_radix(1), weighted_choice with all-zero weights
A count has a natural meaning at zeroThat meaning, not a failuretake(0), chunks(0) and repeated(0) give nothing; a shift count of 64 or more shifts every bit out
The environment refuses: files, network, processesAn Error with the matching kind (ENOENT, ETIMEDOUT)read_file, connect
The code is wrongA faultan index out of range with [], integer overflow, a negative shift count, clamp with low above high, reading a flag the schema never declared

A function does not change its return type to report a bad argument. If it returns a plain value, a bad argument is a bug and faults; if it already returns T? or T!, a bad argument returns null or EINVAL. A caller who cannot tell whether a value is valid checks it first or calls the form with a fallback, such as get_or(index, x) for [].