nbos

nbos

https://git.tonybtw.com/nbos.git git://git.tonybtw.com/nbos.git
1,731 bytes raw
1
#ifndef NB_ERROR_H
2
#define NB_ERROR_H
3
4
#include <stddef.h>
5
#include <stdint.h>
6
7
typedef enum : uint8_t {
8
    RESOLVE_OK = 0,
9
    RESOLVE_E_CYCLE,
10
    RESOLVE_E_MISSING_DEP,
11
    RESOLVE_E_DUPLICATE_NAME,
12
    RESOLVE_E_OOM,
13
} resolve_error_kind;
14
15
typedef struct {
16
    resolve_error_kind kind;
17
    const char        *pkg_name;
18
    const char        *dep_name;
19
} resolve_error;
20
21
#define RESOLVE_OK_VAL ((resolve_error){ .kind = RESOLVE_OK })
22
23
typedef enum : uint8_t {
24
    FETCH_OK = 0,
25
    FETCH_E_NETWORK,
26
    FETCH_E_HASH_MISMATCH,
27
    FETCH_E_IO,
28
} fetch_error_kind;
29
30
typedef struct {
31
    fetch_error_kind kind;
32
    const char      *url;
33
    const char      *expected_sha;
34
    const char      *actual_sha;
35
    int              errno_val;
36
} fetch_error;
37
38
#define FETCH_OK_VAL ((fetch_error){ .kind = FETCH_OK })
39
40
typedef enum : uint8_t {
41
    RUN_OK = 0,
42
    RUN_E_SPAWN,
43
    RUN_E_NONZERO,
44
    RUN_E_IO,
45
} run_error_kind;
46
47
typedef struct {
48
    run_error_kind kind;
49
    int            exit_code;
50
    const char    *log_path;
51
    int            errno_val;
52
} run_error;
53
54
#define RUN_OK_VAL ((run_error){ .kind = RUN_OK })
55
56
typedef enum : uint8_t {
57
    REALIZE_OK = 0,
58
    REALIZE_E_FETCH,
59
    REALIZE_E_BUILD,
60
    REALIZE_E_SANDBOX,
61
    REALIZE_E_STORE,
62
} realize_error_kind;
63
64
typedef struct {
65
    realize_error_kind kind;
66
    const char        *pkg_name;
67
    union {
68
        fetch_error fetch;
69
        run_error   run;
70
        int         errno_val;
71
    };
72
} realize_error;
73
74
#define REALIZE_OK_VAL ((realize_error){ .kind = REALIZE_OK })
75
76
void resolve_error_print(const resolve_error *e);
77
void fetch_error_print(const fetch_error *e);
78
void run_error_print(const run_error *e);
79
void realize_error_print(const realize_error *e);
80
81
#endif