Home / Learn / 7 Results and failures

Release v0.4.0Edition 0.2

7.11 Recap and reference

Page 12 of 12

7.11.1 For agents

Every diagnostic of Common mistakes is available as JSON with una --json check .. For Forgetting the clause:

json
{"schema":"una.diagnostics/1","diagnostics":[{"schema":"una.diagnostic/1","code":"U3007","severity":"error","domain":"authority","message":"`parse_order` can fail with `OrderError`; handle the failure with an `if error` clause, or wrap the call in `attempt`","primary":{"file":"src/orders.una","start":{"line":58,"col":15},"end":{"line":58,"col":32}},"related":[],"repairs":[],"explain":"una explain U3007"}],"fixable":0}

repairs is empty because the right clause depends on intent, which only the author knows. U0101 for a clause on the same line (the clause on the same line) and U3009 for a missing fails (a public function that fails without saying so) carry exact edits, which una fix . applies. The compact rule: a call that can fail is the whole expression of its statement, followed by if error … and then if none … on their own lines, or is wrapped in attempt, which gives a Result.

7.11.2 Recap

  • A value that may be missing is an Option[T], Some(value) or None: take it apart with when, or use or_else.
  • A failure is a value of a sum kind you declare, whose variants carry what a person needs.
  • A header declares at most one error kind with fails, or fails of p. A pub function must declare it; a private one may leave it to inference.
  • A call that can fail is the whole expression of its statement, and its handling clauses follow on their own lines: if error first, then if none.
  • use carries on, pass hands on the same kind, fail V(cause: error) translates.
  • attempt keeps the outcome of one call as a Result, Ok or Err.
  • checked is a budgeted run-time test for facts no proof can establish. Use it once, where data enters; prefer a guard when you can.
  • Give every failure path an example.

7.11.3 Reference

Next:8 Choosing