Landin library reference discuss source

hosted/system/failures.ldn

1--  Words for whatever a program over the hosted services fails with: an
2--  errno from `platform/posix`, which words its own, or a core library
3--  failure, which `core/failure` words.  The two meet here rather than in
4--  the system layer, which imports nothing above it (D1951).
5
6import core/cache
7import core/failure
8import core/io
9import core/line
10import core/mem
11import core/net
12import core/text
13import core/tree
14import platform/posix
15
16fixed if compiler.os <> windows then
17    --- A failure of a program over the hosted services: an errno, or one of
18    --- the core library's failures, which every provider over them also
19    --- reports.
20    public reason: type = posix.errno | failure.reason
21
22    --  `posix.words` words an errno and `failure.words` a library failure.
23    --- A short English phrase for a failure (D582), in lower case but for a
24    --- name's own capitals and with no final stop, so that it reads after a
25    --- subject and a colon.  The phrase is static text: it borrows nothing and
26    --- is never freed.
27    public words: (problem: reason) -> (phrase: []u8) =
28        --  An arm names one atom, so each library atom has its own, and what
29        --  is left is an errno: an atom added to `failure.reason` without an
30        --  arm here is refused where the rest is passed to `posix.words`.
31        phrase = match problem
32            mem.out_of_bounds: failure.words(mem.out_of_bounds)
33            mem.empty: failure.words(mem.empty)
34            mem.not_empty: failure.words(mem.not_empty)
35            mem.out_of_memory: failure.words(mem.out_of_memory)
36            mem.not_found: failure.words(mem.not_found)
37            tree.invalid_children: failure.words(tree.invalid_children)
38            tree.too_many_nodes: failure.words(tree.too_many_nodes)
39            tree.too_many_leaves: failure.words(tree.too_many_leaves)
40            io.no_access: failure.words(io.no_access)
41            io.io_failed: failure.words(io.io_failed)
42            io.is_a_directory: failure.words(io.is_a_directory)
43            io.already_exists: failure.words(io.already_exists)
44            io.not_a_terminal: failure.words(io.not_a_terminal)
45            net.invalid_address: failure.words(net.invalid_address)
46            net.refused: failure.words(net.refused)
47            net.unreachable: failure.words(net.unreachable)
48            net.address_in_use: failure.words(net.address_in_use)
49            net.address_unavailable: failure.words(net.address_unavailable)
50            net.timed_out: failure.words(net.timed_out)
51            net.disconnected: failure.words(net.disconnected)
52            text.invalid_text: failure.words(text.invalid_text)
53            text.invalid_number: failure.words(text.invalid_number)
54            text.number_overflow: failure.words(text.number_overflow)
55            text.invalid_format: failure.words(text.invalid_format)
56            text.invalid_scalar: failure.words(text.invalid_scalar)
57            cache.misaligned: failure.words(cache.misaligned)
58            cache.bad_line: failure.words(cache.bad_line)
59            line.unsupported_rate: failure.words(line.unsupported_rate)
60            line.unsupported_format: failure.words(line.unsupported_format)
61            _ (rest): posix.words(rest)
62        end match
63    end words
64end if