OxL Reference

6.5 Errors

There are no exceptions. An error is a value of a type marked @error, returned through a union.

oxl
@error data NotFound { what: str }
@error enum PayError { Declined(reason: str), Fraud }

fn charge(card: Card, sum: Money) -> Receipt | PayError | NetError  net {
  let token = Vault.tokenize(card)?          // ? propagates the errors of the call
  if sum <= Money.zero() { fail PayError.Declined("zero sum") }
  Bank.pay(token, sum)
}
  • fail e returns the error e from the function; the type of e MUST be included in the return type.
  • e? for e: T | E1 | …: on an error returns it from the function, otherwise yields T. The errors MUST be included in the return type of the function.
  • e? for e: T? (without errors) returns none from a function that returns an optional.
  • Mandatory handling. An expression statement whose type contains an @error type is a compile error. Handling: match, ?, !>, if … is, assignment to a variable that is then handled, or an explicit discard _ = e.
  • Network errors. Every rpc call, actor message and cluster operation adds NetError to the result:
oxl
type NetError = Timeout | Unavailable | Cancelled | AccessDenied | ProtocolError

ProtocolError is @error data ProtocolError { msg: str, code: i32 }, where code is a gRPC status code. The notations ProtocolError.Internal (§6.6), ProtocolError.InvalidArgument (§9.4) and ProtocolError.Unimplemented are associated constants — values of this type with the codes 13, 3 and 12; they can be compared and matched in the same way as variants (D-8052; DIV-004; D-2901).

The result of a cluster operation contains NetError if the operation talks to other nodes and may fail to get an answer: among the cluster.* operations (§12.6) lock and lockFenced are such; operations executed locally (self, members, find, pick, leader, ids, now, shards) do not add NetError (D-7520).

  • Trace: in profiles with trace = true every ? adds a frame (function, file, line) to the error; available as err.trace().

fail-type, question-context, unhandled-error

See also

Source: docs/spec/oxl-standard.en.md