Go Got It Right: Errors as Values
Go developers already internalized something many others still resist: errors are values. An error is just a piece of information — not fundamentally different from any other data your program works with.
Go made a bold choice by rejecting exceptions in favor of explicit error values. This gives you:
- Predictable control flow: no hidden jumps or stack unwinding
- Local reasoning: you know exactly where errors come from
- Composable error handling: errors are just data you can transform
user, err := getUser(123)
if err != nil {
return fmt.Errorf("failed to get user: %w", err)
}
permissions, err := getPermissions(user.ID)
if err != nil {
return fmt.Errorf("failed to get permissions: %w", err)
}
This is explicit, honest, and debuggable. But it’s also… repetitive.
The Go Patterns We All Know (And How Rye Improves Them)
Let’s look at the common Go error handling patterns and see how Rye maps to each one.
The Wrap-and-Return Pattern: ^check
Go pattern:
result, err := someOperation()
if err != nil {
return fmt.Errorf("context message: %w", err)
}
Rye equivalent:
some-operation |^check "context message"
Can we do this in Go?
Almost, but not quite. We can write a function that accepts a value and an error, but that function can never trigger an early return in the caller:
func Check[T any](value T, err error, message string) (T, error) {
if err != nil {
return *new(T), fmt.Errorf("%s: %w", message, err)
}
return value, nil
}
That’s the crux of it. On error, ^check doesn’t just produce an error value for you to check — it exits the enclosing Rye function immediately and returns to its caller. No plain function in Go can do that; only the language’s own if err != nil { return ... } can reach through a function boundary like that. So a Go helper built the same way still needs the boilerplate back at the call site:
user, err := Check(getUser(123), "failed to get user")
if err != nil {
return err
}
The boilerplate doesn’t disappear — it just moves one line over. That gap is exactly what Rye calls a returning function, and it’s worth slowing down on, because it’s the actual interesting mechanism here, not just a syntax trick specific to error handling.
The Returning Functions Mechanism, In More Depth
Rye marks these with a ^ prefix by convention — ^check, ^ensure. What that prefix signals is: this function, when it fails, doesn’t return a value to the pipe — it unwinds and exits the Rye function that called it. Everything after it in that function’s body simply doesn’t run.
This is not a new idea in the abstract. Non-local return has prior art:
- Rust’s
?operator does something very similar forResultandOption— but it’s compiler-desugared syntax wired specifically to those two types. You can’t define a new one; extending?to a new “shape” of early-return has been the subject of years of internal Rust language design discussion, precisely because it’s baked into the type system rather than being an ordinary callable. - Common Lisp’s
block/return-fromis an explicit, named, structured non-local exit — closer in spirit, but it’s a special form, not a function value. You can’t pass it around or build new variants out of ordinary function definitions. - Smalltalk blocks can return out of the method that created them, which is elegant but tied specifically to blocks and their enclosing method — again, a language feature, not something arbitrary code opts into.
What’s different about Rye’s version isn’t that non-local return exists — it’s where the capability lives. In all three examples above, it’s a special form or compiler feature wired to one type or construct. In Rye, it’s a convention: a builtin function is either a returning function or it isn’t, and the interpreter treats the ^ prefix consistently across all of them. ^check and ^ensure aren’t two special cases hardcoded independently — they’re two instances of the same mechanism.
The honest limitation: today, this lives at the builtin level — ^check and ^ensure are native functions with special handling in Rye’s Go-implemented evaluator, not something you can currently define from ordinary Rye code. So “add a new returning function” today means writing a new Go-level builtin that follows the convention, not writing Rye. Extending the same mechanism to plain Rye-defined functions is a natural next step and, as far as I know, not a fundamental obstacle — but it isn’t there yet, and it’s worth being upfront about that rather than implying anyone can casually mint new ^-functions in userspace today.
This is really the core trade-off of the whole post: ^check isn’t a library trick, it’s a language-level mechanism. In exchange, the boilerplate genuinely disappears at the call site rather than just moving one line over — but only for the finite set of returning functions the language (currently) provides.
The Validation Pattern: ^ensure
Go pattern:
if userAge <= 0 {
return fmt.Errorf("age must be positive")
}
Rye equivalent:
user-age > 0 |^ensure "age must be positive"
Same story as ^check — ^ensure also does a non-local return on failure, so it can’t be reproduced as a plain Go function either.
The Recovery Pattern: fix
Go pattern:
config, err := loadConfig("app.yml")
if err != nil {
config = defaultConfig()
}
Rye equivalent:
config: load-config "app.yml" |fix { default-config }
Unlike ^check, fix doesn’t need to return to the caller — it just substitutes a value in place. That means it can be written as an ordinary Go function:
func Fix[T any](value T, err error, fallback func() T) T {
if err != nil {
return fallback()
}
return value
}
// Usage:
config := Fix(loadConfig("app.yml"), func() Config { return defaultConfig() })
The Conditional Execution Pattern: continue
Go pattern:
user, err := getUser(123)
if err == nil {
processUser(user)
}
Rye equivalent:
get-user 123 |continue { user -> process-user user }
Also not a returning function, so a direct Go equivalent works fine:
func Continue[T any](value T, err error, fn func(T)) {
if err == nil {
fn(value)
}
}
// Usage:
Continue(getUser(123), func(user User) { processUser(user) })
The Either Pattern: fix\either
Go pattern:
result, err := riskyOperation()
if err != nil {
return handleError(err)
} else {
return handleSuccess(result)
}
Rye equivalent:
risky-operation |fix\either { err -> handle-error err } { result -> handle-success result }
The Bigger Picture: Pipeline Error Handling
Here’s where Rye really shines. Look at this typical Go error handling sequence:
func ProcessUser(userID int) (*Result, error) {
user, err := getUser(userID)
if err != nil {
return nil, fmt.Errorf("failed to get user: %w", err)
}
err = validateUser(user)
if err != nil {
return nil, fmt.Errorf("user validation failed: %w", err)
}
permissions, err := getPermissions(user.ID)
if err != nil {
return nil, fmt.Errorf("failed to get permissions: %w", err)
}
err = checkAdminAccess(permissions)
if err != nil {
return nil, fmt.Errorf("admin access denied: %w", err)
}
result, err := processRequest(user, permissions)
if err != nil {
return nil, fmt.Errorf("request processing failed: %w", err)
}
return result, nil
}
In Rye, this becomes:
process-user: fn { user-id } {
get-user user-id
|^check "failed to get user"
|validate-user
|^check "user validation failed"
|get-permissions
|^check "failed to get permissions"
|check-admin-access
|^check "admin access denied"
|process-request
|^check "request processing failed"
}
The Rye version has the same explicit error handling as Go — every step can fail, and failures carry context — just without the syntactic noise.
Advanced Go Patterns and Their Rye Equivalents
Retry Logic
Go pattern:
func RetryOperation(attempts int) error {
for i := 0; i < attempts; i++ {
err := riskyOperation()
if err == nil {
return nil
}
if i == attempts-1 {
return err
}
time.Sleep(time.Duration(i) * time.Second)
}
return nil
}
Rye equivalent:
retry 3 { risky-operation }
Timeout Handling
Go pattern:
func WithTimeout(timeout time.Duration) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
done := make(chan error, 1)
go func() {
done <- slowOperation()
}()
select {
case err := <-done:
return err
case <-ctx.Done():
return ctx.Err()
}
}
Rye equivalent:
timeout 5000 { slow-operation } ; 5 second timeout
What Go Developers Would Recognize
If you’re a Go developer, Rye’s error handling should feel familiar, because it follows the same principles:
- Errors are values — just like Go, Rye treats errors as data
- Explicit handling — every error is handled at a specific point
- Composable — error handling functions compose together
- No hidden control flow — nothing jumps around behind your back
The difference is that some of Rye’s combinators (^check, ^ensure) are returning functions — they can reach into the caller and return early, which is exactly the piece no plain Go function, generic or not, can express. The rest (fix, continue) are closer to what you could write yourself in Go today — Rye just gives them a name and a pipe.
Are There Other Returning Functions Worth Having?
^check and ^ensure are the two Rye ships with today. Since the mechanism is a convention rather than a one-off special case, it’s fair to ask what else might be worth exiting a function early for — a ^retry-or-fail that gives up and returns after N attempts, a ^require-auth that exits with a specific error if a permission check fails, something like Go’s panic/recover boundary but scoped to a single value check. I don’t have a strong opinion yet on which of these are actually worth adding versus just composing from ^check — curious what Go developers reach for by hand often enough that it’d be worth being a builtin instead.
The Trade-Off, Plainly
Rye doesn’t change Go’s fundamental insight that errors should be explicit values — it just moves some of Go’s most repeated patterns into the language itself, via a small set of returning functions rather than new syntax per pattern. That buys you less boilerplate, at the cost of ^check and ^ensure being a mechanism you have to learn rather than a package you could go get — and, today, a mechanism that lives at the builtin level rather than something you can extend from ordinary Rye code. Whether that trade is worth it probably depends on how many times a day you type if err != nil, and how much you’d use a returning function once you could write your own.