1-- Words for a person: a short English phrase for each failure atom the
2-- core library raises, for a program that reports a failure as text. It
3-- holds no state and allocates nothing, and a program that never calls
4-- `words` carries none of it (D296).
5
6import core/io
7import core/map
8import core/mem
9import core/net
10import core/text
11import core/tree
12
13--- Every atom a `core` module fails with: the set `words` takes. A call's
14--- failure, `problem` in its `else (problem)`, widens to it whatever subset
15--- of these atoms the call declares. A set that also holds an atom of the
16--- program's own does not: a `match` arm names each library atom and passes
17--- that atom on, since a `_` arm leaves the set as it was.
18public reason: type = mem.out_of_bounds | mem.empty | mem.full | mem.not_empty
19 | mem.out_of_memory | map.missing | map.end_of_entries
20 | tree.no_such_node | tree.invalid_children
21 | tree.too_many_nodes | tree.too_many_leaves
22 | io.not_found | io.no_access | io.io_failed
23 | io.no_argument | io.already_exists | io.no_variable
24 | io.line_too_long | io.not_a_terminal
25 | net.invalid_address | net.refused | net.unreachable
26 | net.address_in_use | net.address_unavailable
27 | net.timed_out | net.disconnected | text.past_end
28 | text.invalid_text | text.invalid_number
29 | text.number_overflow | text.no_space
30 | text.invalid_format
31
32--- A short English phrase for a library failure, in lower case with no
33--- final stop, so that it reads after a subject and a colon as
34--- `settings: not found` does. The phrase is static text: it borrows
35--- nothing and is never freed. Every atom of `reason` has its own phrase,
36--- and the phrases are fixed: a program may compare them, and no locale
37--- changes them.
38public words: (problem: reason) -> (phrase: []u8) =
39 phrase = match problem
40 mem.out_of_bounds: "index out of bounds"
41 mem.empty: "nothing to take"
42 mem.full: "no room for another item"
43 mem.not_empty: "storage still holds items"
44 mem.out_of_memory: "out of memory"
45 map.missing: "no such key"
46 map.end_of_entries: "no more entries"
47 tree.no_such_node: "no such node"
48 tree.invalid_children: "children outside the tree"
49 tree.too_many_nodes: "too many nodes"
50 tree.too_many_leaves: "too many leaves"
51 io.not_found: "not found"
52 io.no_access: "permission denied"
53 io.io_failed: "input or output failed"
54 io.no_argument: "no such argument"
55 io.already_exists: "already exists"
56 io.no_variable: "no such variable"
57 io.line_too_long: "line too long"
58 io.not_a_terminal: "not a terminal"
59 net.invalid_address: "invalid address"
60 net.refused: "connection refused"
61 net.unreachable: "address unreachable"
62 net.address_in_use: "address in use"
63 net.address_unavailable: "address not available"
64 net.timed_out: "timed out"
65 net.disconnected: "peer disconnected"
66 text.past_end: "past the end"
67 text.invalid_text: "invalid UTF-8"
68 text.invalid_number: "not a number"
69 text.number_overflow: "number out of range"
70 text.no_space: "no room for the output"
71 text.invalid_format: "template does not fit its values"
72 end match
73end words