1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use LazyLock;
use EnumMap;
use crateSystemErrno;
/// This map is derived off of what coreutils uses in printing errors. This is
/// equivalent to `strerror`, but as strings with constant lifetime.
//
// PORT NOTE: Zig builds this at comptime via `@hasField`/`@field` reflection over
// `SystemErrno`. Rust has no struct-field reflection, so we build it once at first
// access via `LazyLock`. The per-OS (name → message) string tables themselves
// live canonically in `bun_core::coreutils_error_map` (a `phf::Map` keyed by
// errno *name*); here we just project that table onto the platform's typed
// `SystemErrno` enum so callers get an O(1) `EnumMap` index. Variants whose
// names have no entry in the bun_core table fall back to `UNKNOWN`, matching
// the Zig `@hasField` filter.
pub static COREUTILS_ERROR_MAP: =
new;
/// Sentinel default for errnos with no coreutils label. Stored by pointer
/// identity in `COREUTILS_ERROR_MAP` so `get()` can distinguish "unmapped"
/// from a real entry.
pub const UNKNOWN: &str = "unknown error";
/// Spec: Zig `coreutils_error_map.get(errno)` returns `?[]const u8`. The Rust
/// `EnumMap` is total, so we treat the `UNKNOWN` sentinel as `None` to preserve
/// the Zig fallthrough behaviour (callers format `"unknown error {errno}"`).
// ported from: src/sys/coreutils_error_map.zig