nbos

nbos

https://git.tonybtw.com/nbos.git git://git.tonybtw.com/nbos.git
2,853 bytes raw
1
#include "error.h"
2
3
#include <stdio.h>
4
#include <string.h>
5
6
void resolve_error_print(const resolve_error *e) {
7
    switch (e->kind) {
8
        case RESOLVE_OK:
9
            return;
10
        case RESOLVE_E_CYCLE:
11
            fprintf(stderr, "nb: dependency cycle detected at '%s'\n", e->pkg_name);
12
            return;
13
        case RESOLVE_E_MISSING_DEP:
14
            fprintf(stderr, "nb: package '%s' depends on '%s' which is not in the package list\n", e->pkg_name, e->dep_name);
15
            return;
16
        case RESOLVE_E_DUPLICATE_NAME:
17
            fprintf(stderr, "nb: duplicate package name '%s' (two recipes export the same name)\n", e->pkg_name);
18
            return;
19
        case RESOLVE_E_OOM:
20
            fprintf(stderr, "nb: out of memory while resolving packages\n");
21
            return;
22
    }
23
}
24
25
void fetch_error_print(const fetch_error *e) {
26
    switch (e->kind) {
27
        case FETCH_OK:
28
            return;
29
        case FETCH_E_NETWORK:
30
            fprintf(stderr, "nb: network error fetching %s: %s\n", e->url, strerror(e->errno_val));
31
            return;
32
        case FETCH_E_HASH_MISMATCH:
33
            fprintf(stderr, "nb: hash mismatch for %s\n", e->url);
34
            fprintf(stderr, "  expected: %s\n", e->expected_sha);
35
            fprintf(stderr, "  actual:   %s\n", e->actual_sha);
36
            return;
37
        case FETCH_E_IO:
38
            fprintf(stderr, "nb: I/O error fetching %s: %s\n", e->url, strerror(e->errno_val));
39
            return;
40
    }
41
}
42
43
void run_error_print(const run_error *e) {
44
    switch (e->kind) {
45
        case RUN_OK:
46
            return;
47
        case RUN_E_SPAWN:
48
            fprintf(stderr, "nb: failed to spawn process: %s\n",
49
                    strerror(e->errno_val));
50
            return;
51
        case RUN_E_NONZERO:
52
            fprintf(stderr, "nb: process exited %d (log: %s)\n",
53
                    e->exit_code, e->log_path);
54
            return;
55
        case RUN_E_IO:
56
            fprintf(stderr, "nb: I/O error: %s\n", strerror(e->errno_val));
57
            return;
58
    }
59
}
60
61
void realize_error_print(const realize_error *e) {
62
    switch (e->kind) {
63
        case REALIZE_OK:
64
            return;
65
        case REALIZE_E_FETCH:
66
            fprintf(stderr, "nb: failed to realize '%s' (fetch):\n  ", e->pkg_name);
67
            fetch_error_print(&e->fetch);
68
            return;
69
        case REALIZE_E_BUILD:
70
            fprintf(stderr, "nb: failed to realize '%s' (build):\n  ", e->pkg_name);
71
            run_error_print(&e->run);
72
            return;
73
        case REALIZE_E_SANDBOX:
74
            fprintf(stderr, "nb: failed to set up sandbox for '%s': %s\n",
75
                    e->pkg_name, strerror(e->errno_val));
76
            return;
77
        case REALIZE_E_STORE:
78
            fprintf(stderr, "nb: store error for '%s': %s\n",
79
                    e->pkg_name, strerror(e->errno_val));
80
            return;
81
    }
82
}