louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
ADR 0024: Errors as values
Status: Accepted by the project owner — 2026-10-11 (issue gabla108/louise#87, PR gabla108/louise#90); still needs engineering review (gabla108/louise#44). It completes the error-handling part of ADR 0001, which says only that panics are not tracked in effect rows.
Context
Issue gabla108/louise#87 asks for errors as values: a result type you match on, Ok or Error. The prelude already had Result<a, e> { Ok(a) Error(e) }, and std/result had map, try (for use) and unwrap_or. What was missing:
- a convention. The standard library and the packages each signalled failure in their own way.
string.to_intreturnedOption<Int>,argon2.verifyreturnedBool(a malformed hash looked like a wrong password), the demo'sadd_userreturnedFalsefor a taken name, andqsortpanicked when its C library ran out of memory. - a small library. Without
map_error,allor a conversion fromOption, code fell back to nestedmatches, so the convention was not cheap to follow. - prelude parity with
Option:ResulthadEq,ShowandDebug, but notOrdorHash, so it could not be a dictionary key or be sorted.
Decision
The convention
| A function... | returns | Example |
|---|---|---|
| can fail, and the caller should handle why | Result<a, e> | string.to_int, net.connect, argon2.verify |
| may find nothing, and nothing is not a failure | Option<a> | dict.get, http.header, os.env |
| answers a yes-or-no question | Bool | string.starts_with, dict.has |
| meets a broken invariant (a bug) | panics | an index out of range, result.expect on an Error |
| leaves the decision to a handler chosen by the caller | an effect operation | a fail effect, as in the tutorial |
Rules that follow:
- The error type says why. Libraries that only report a message use
String, asstd/netandstd/bytesalready did. Code whose callers branch on the reason defines a sum type (the demo'sRegisterErrorandLoginError).()as an error type is avoided: it gives the caller nothing to log. - Callers choose between
OptionandResult.option.to_result(o, reason)andresult.to_option(r)convert in both directions, so a function keeps the type that describes it. - Chaining is done with
use, not new syntax.use v <- result.try(r)stops at the firstError, as Gleam does. A?operator was considered and rejected:usealready covers it, works for any type, and keeps one way to write it. - Raw FFI bindings stay raw. Generated bindings return what the C function returns (
sortkit.sk_vec_push -> Bool). The Louise-facing wrapper turns status codes intoResult(qsort.sort). - Private externs may still return tuples (
string.parse_int -> (Bool, Int),os.env_raw): the public function converts them. Changing the extern convention is not needed for this.
The library
std/result (Gleam's names, except where Louise already had a Rust name):
| Function | |
|---|---|
is_ok, is_error | predicates |
map, map_error, replace_error | change one side |
try | continue on Ok; for use |
flatten | Result<Result<a, e>, e> to Result<a, e> |
unwrap_or, unwrap_or_else | the value, or a default (computed from the reason with unwrap_or_else) |
expect(r, message) | the value, or a panic with message and the reason (Debug); for results that are Ok unless there is a bug |
to_option | drop the reason |
all, values | lists of results: the values or the first Error; the values of the Oks |
There is no panicking unwrap without a message. expect makes the caller say why the result cannot be an error, and the panic message carries it.
std/option gets the matching pieces: is_none, then (continue on Some, for use), to_result, and values.
The prelude adds Ord<Result<a, e>> (Ok before Error, then the payloads, as a derived Ord would) and Hash<Result<a, e>>. There is no Default for Result: neither side is a natural default.
API changes
| Before | After |
|---|---|
string.to_int(s) -> Option<Int> | -> Result<Int, String>; the error is not an integer: "<s>" |
argon2.verify(password, encoded) -> Bool | -> Result<Bool, String>: Ok(False) on a mismatch, an Error when encoded cannot be checked |
qsort.sort(xs, compare) -> List<Int> (panicked when out of memory) | -> Result<List<Int>, String> |
demo: the users effect's add_user(user) -> Bool | -> Result<(), RegisterError> (Error(NameTaken)) |
demo: PORT or MAX_CONNECTIONS that is not a number was silently replaced by the default | main prints why and stops |
actor.call only, which panics without a reply | new actor.try_call(to, request, timeout) -> Result<r, CallError> (Error(Timeout)); call stays, built on it, for an actor that must answer |
Consequences
- Callers of
string.to_intandargon2.verifymust change: aSome/Nonematch becomesOk/Error, andif argon2.verify(...)becomes amatch. Every caller in this repository is updated. - A login now tells a wrong password apart from a corrupted stored hash: the demo answers the first with 401 and logs the second with 500.
result.allandresult.valuesare not tail-recursive, likelist.map: they use stack in proportion to the list.
Left open
actor.try_callreports onlyTimeout. Telling a stopped actor apart (Gleam'sCalleeDown) needs a monitor per call, and the process API has nodemonitorto remove it afterwards, so each call would leave one behind. For the same reason, a reply that arrives after the timeout stays in the caller's mailbox until the caller stops. Both need a way to close a subject or remove a monitor in the runtime and the interpreter. Note — 2026-11-01:process.demonitorexists since gabla108/louise#414 (ADR 0004, Note — 2026-11-01), in the runtime and the interpreter, so the reason given here no longer holds:try_callcould monitor the callee anddemonitor_flushit after the reply or the timeout, and reportCalleeDown. It still reports onlyTimeout; that change, and closing a subject so that a late reply is dropped, remain open.- Some settings use
-1for "no limit" (http.Settings.connections, receive timeouts). That is absence, not failure, so it is outside this ADR;Option<Int>would make it explicit.