aboutsummaryrefslogtreecommitdiff
path: root/mirai/crimson/constants/types.zig
blob: d0ffdf2abba46d732abf556874f4a97f3febfe51 (plain)
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
50
51
//! Exception Types

pub const ExceptionType = enum(u8) {
    breach = 0,
    forbidden = 1,
    overflow = 2,
    shatter = 3,
    missing = 4,
    critical = 5,
    software = 6,
    resource = 7,
    guard = 8,
    collapse = 9,

    pub fn is_recoverable(self: ExceptionType) bool {
        return switch (self) {
            .breach, .forbidden, .overflow, .shatter, .missing, .software, .resource, .guard => true,
            .critical, .collapse => false,
        };
    }

    pub fn name(self: ExceptionType) []const u8 {
        return switch (self) {
            .breach => "Breach",
            .forbidden => "Forbidden",
            .overflow => "Overflow",
            .shatter => "Shatter",
            .missing => "Missing",
            .critical => "Critical",
            .software => "Software",
            .resource => "Resource",
            .guard => "Guard",
            .collapse => "Collapse",
        };
    }

    pub fn description(self: ExceptionType) []const u8 {
        return switch (self) {
            .breach => "Memory access failure",
            .forbidden => "Illegal operation",
            .overflow => "Arithmetic exception",
            .shatter => "Debug or breakpoint",
            .missing => "Resource not available",
            .critical => "System-level interrupt",
            .software => "Software-raised exception",
            .resource => "Resource limit exceeded",
            .guard => "Guarded resource violation",
            .collapse => "Unrecoverable error",
        };
    }
};