Debian Codegraph @

time/chrono/error.ha

raw
1 // SPDX-License-Identifier: MPL-2.0
2 // (c) Hare authors <https://harelang.org>
3
4 use encoding::utf8;
5 use fmt;
6 use fs;
7 use io;
8
9 // All possible errors returned from this module.
10 export type error = !(tscmismatch | utciniterror);
11
12 // Converts an [[error]] into a human-friendly string. The result may be
13 // statically allocated.
14 export fn strerror(e: error) const str = {
15 static let buf: [92]u8 = [0...];
16 match (e) {
17 case let e: tscmismatch =>
18 return fmt::bsprintf(buf,
19 "Timescale mismatch: {}, {}",
20 e.0.abbr,
21 e.1.abbr,
22 )!;
23 case let e: utciniterror =>
24 return fmt::bsprintf(buf,
25 "UTC initialization: {}",
26 match (e) {
27 case let e: fs::error =>
28 yield fs::strerror(e);
29 case let e: io::error =>
30 yield io::strerror(e);
31 case let e: utf8::invalid =>
32 yield utf8::strerror(e);
33 },
34 )!;
35 };
36 };