Developer preview. Vela, Facet, and Quire are pre-release and in active development — syntax, APIs, and availability may change, and they are not yet generally available.
SStretch Dev Docs
Vela

Error Handling

Stage-0 `Option` / `Result` values and the postfix `?` operator.

1. Error values, not exceptions

The language model in seed docs uses two ADTs for recoverable failure:

type Option:
    Some(value)
    None

type Result:
    Ok(value)
    Err(error)

Option and Result are builtins in seed examples and in std/option.vela.

2. ? for propagation

Postfix ? unwraps

  • Some(v) -> v
  • Ok(v) -> v

and returns early on:

  • None
  • Err(e)
fn checked_div(a, b):
    if b == 0:
        return Err("divide by zero")
    return Ok(a / b)

fn ratio(a, b, c):
    x = checked_div(a, b)?
    y = checked_div(x, c)?
    return Ok(y)

print(ratio(100, 5, 2))
print(ratio(100, 0, 2))
Ok(10)
Err("divide by zero")

3. Option ?

fn first_even(xs):
    for x in xs:
        if x % 2 == 0:
            return Some(x)
    return None

fn half_first_even(xs):
    n = first_even(xs)?
    return Some(n / 2)

print(half_first_even([1, 5, 8]))
print(half_first_even([1, 5, 9]))
Some(4)
None

4. Valid ? operands only

? is defined only for Option/Result forms in Stage-0.

fn f():
    return 1?

This is invalid at runtime in seed behavior.

5. Helper APIs from std/option.vela

Helpers present in the std source include:

  • is_some, is_none, unwrap_or, map_option, and_then, or_else
  • is_ok, is_err, unwrap_or_default, map_result, map_err, result_to_option

They are intentionally tiny and keep the algebraic flow explicit.

6. Assertions

assert(cond) and assert(cond, message) are also available builtins. A failed assertion aborts with the provided message.

The docs do not define try/catch; error handling is explicit by values and pattern matching.