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)orNone: take it apart withwhen, or useor_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, orfails of p. Apubfunction 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 errorfirst, thenif none. usecarries on,passhands on the same kind,fail V(cause: error)translates.attemptkeeps the outcome of one call as aResult,OkorErr.checkedis 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
- Construct pages:
fails,fail,if errorandif none,attempt,checkedand the escape budget,predicate,example - Prelude:
Option,Result,or_else,is_some,is_ok,to_int,find,parse_int,ParseError - Configuration:
[escape_budget] checked_per_module - Diagnostics: U0101, U0102, U1001, U2001, U2007, U2016 (an opaque predicate called outside
checked), U3007, U3008, U3009, U3013, U5001 (a refinement the verifier refutes), U7003 (checkedbeyond the escape budget), U3025 and U3026 (edition0.3: a clause orattempton a call that cannot fail), and the stops at run time: U6001 (mainfailed with its declared kind), U6003 (call depth or memory), U6004 (an HTTP header value with a control character), U6005 (host text that is not valid UTF-8) and U8001 (an internal error of una) - Specification: errors, types, the standard library, text
Next:8 Choosing