People bring habits with them. After years of Go or Python, a first Rye loader often looks like this: try, is-error, a long concatenated string, and something like die. It works on the happy path. It also does and says things at the wrong level.
eval-rye-file-OLD: fn { path } {
src: try { Read file path }
if is-error src {
^fail "Error loading config file, cannot read " ++ path ++ ": " ++ message? src
}
code: try { load src }
if is-error code {
^fail "Error loading config file, cannot parse " ++ path ++ ": " ++ message? code
}
c: try { context code }
if is-error c {
^fail "Error loading config " ++ path ++ ": " ++ message? c
}
c
}
load-config-OLD: fn { path } {
eval-rye-file-OLD path
}
Rye has no die builtin — I used ^fail here so the example actually runs — but the habit is the same, and many ports would exit at that point. The problem is not that this is longer. It talks about config in a function that is supposed to evaluate any Rye file. It pastes the path and the inner message into a new string, so the original error stops being a cause and becomes text. And if you really do stop the process there, a REPL, a server, or a caller that wanted a default no longer gets a say. fix cannot recover from an exit.
I think of a fuel sensor that can’t read the tank, so it turns off the engine. The sensor is the one that knows what failed. It is not the one that should decide what happens next.
In an earlier post — What are the filter / map / reduce of error handling? — I looked at names like check and fix. This post is that idea in a short, concrete program, not just the vocabulary.
eval-rye-file: fn { path } {
Read file path
|^check "Can't read a file"
|load
|^check "Not a proper Rye syntax"
|context
|^check "Not a proper context"
}
load-config: fn { path } {
cfg: eval-rye-file path
|^check "Can't read config"
cfg
}
load-config rye .Args\raw?
Each step adds only what it knows. Read already carries the path and the OS reason. eval-rye-file says it couldn’t read a file, or the text wasn’t Rye, or it wasn’t a context. It does not assume this file is a config — you might reuse the same helper for a plugin or a script. load-config is the first place it’s allowed to say “config”.
That’s failure domain translation: no duplication, and no loss.
Here is a missing file, run as rye . missing.conf.rye (rye . means rye main.rye; the argument is the config path).
The flattened version:
Error: Error loading config file, cannot read missing.conf.rye: `file-uri//Read`: open missing.conf.rye: no such file or directory
The translated version:
Error: Can't read config
Error: Can't read a file
Error: `file-uri//Read`: open missing.conf.rye: no such file or directory
The lowest line already has the path and the reason. You don’t need to paste them into a new sentence. The middle line does not mention config. The outer line does — that’s its job.
And a file bad.conf.rye whose contents are a blank line and then 123conf:
Error: Can't read config
Error: Not a proper Rye syntax
Error: In file main.rye at line 2
SYNTAX ERROR
File: main.rye
Location: line 2, column 4
Error: Missing space after number '123'. Found 'c' immediately after. Numbers must be followed by whitespace.
Source context:
1 |
2 | 123conf
^
3 |
The syntax error survives three levels, still structured, with the source snippet. The flattened version keeps that text too, but only as a substring glued to "Error loading config file, cannot parse bad.conf.rye: ...". One message, the word “config” at the parse layer, the causes no longer a chain you can walk.
A small honesty about File: main.rye: the syntax error is in bad.conf.rye. load parses a string, and the loader attributes the error to the running script — main.rye, because that’s what rye . started. Load file "bad.conf.rye" (the file-URI variant) temporarily sets the script path and reports File: bad.conf.rye. So this is a real misattribution, and a reasonable fix is either a filename hint on load, or writing eval-rye-file with Load file path instead of Read ... |load.
Because load-config returns a failure instead of stopping the process, a caller can choose a policy. The mechanism stays below; the policy lives here:
default-cfg: context { name: "default" port: 8080 }
cfg: load-config "missing.conf.rye" |fix { default-cfg }
print do\in cfg { name }
print do\in cfg { port }
; prints:
; default
; 8080
The same fallback works for bad.conf.rye. A valid good.conf.rye (name: "demo", port: 8080) comes through unchanged. fix leaves success alone; on failure it runs the recovery block and does not return from the enclosing function. (^fix and disarm also exist, if you need an early return or a disarmed error value.)
This is not a claim that Rye invented wrapping, or that it does it better. Rust’s ? and map_err are in the language; crates like anyhow and context are a convenience for the same idea. What I care about is simpler: add only what this layer knows, keep the cause, and leave the policy to a function that has the authority to decide.
If you want to try the current language, the latest release is on GitHub. We’re hoping to reach 800 stars by the end of the year — if Rye is useful to you, a star helps.