Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 /* Error codes */
18 #define GOT_ERR_OK 0
19 #define GOT_ERR_ERRNO 1
20 #define GOT_ERR_NOT_GIT_REPO 2
21 #define GOT_ERR_NOT_ABSPATH 3
22 #define GOT_ERR_BAD_PATH 4
23 #define GOT_ERR_NOT_REF 5
24 #define GOT_ERR_IO 6
25 #define GOT_ERR_EOF 7
26 #define GOT_ERR_DECOMPRESSION 8
27 #define GOT_ERR_NO_SPACE 9
28 #define GOT_ERR_BAD_OBJ_HDR 10
29 #define GOT_ERR_OBJ_TYPE 11
30 #define GOT_ERR_BAD_OBJ_DATA 12
31 #define GOT_ERR_FILE_OPEN 13
32 #define GOT_ERR_BAD_PACKIDX 14
33 #define GOT_ERR_PACKIDX_CSUM 15
34 #define GOT_ERR_BAD_PACKFILE 16
35 #define GOT_ERR_NO_OBJ 17
36 #define GOT_ERR_NOT_IMPL 18
37 #define GOT_ERR_OBJ_NOT_PACKED 19
38 #define GOT_ERR_BAD_DELTA_CHAIN 20
39 #define GOT_ERR_BAD_DELTA 21
40 #define GOT_ERR_COMPRESSION 22
41 #define GOT_ERR_BAD_OBJ_ID_STR 23
42 #define GOT_ERR_WORKTREE_EXISTS 26
43 #define GOT_ERR_WORKTREE_META 27
44 #define GOT_ERR_WORKTREE_VERS 28
45 #define GOT_ERR_WORKTREE_BUSY 29
46 #define GOT_ERR_DIR_OBSTRUCTED 30
47 #define GOT_ERR_FILE_OBSTRUCTED 31
48 #define GOT_ERR_RECURSION 32
49 #define GOT_ERR_TIMEOUT 33
50 #define GOT_ERR_INTERRUPT 34
51 #define GOT_ERR_PRIVSEP_READ 35
52 #define GOT_ERR_PRIVSEP_LEN 36
53 #define GOT_ERR_PRIVSEP_PIPE 37
54 #define GOT_ERR_PRIVSEP_NO_FD 38
55 #define GOT_ERR_PRIVSEP_MSG 39
56 #define GOT_ERR_PRIVSEP_DIED 40
57 #define GOT_ERR_PRIVSEP_EXIT 41
58 #define GOT_ERR_PACK_OFFSET 42
59 #define GOT_ERR_OBJ_EXISTS 43
60 #define GOT_ERR_BAD_OBJ_ID 44
61 #define GOT_ERR_ITER_NEED_MORE 45
62 #define GOT_ERR_ITER_COMPLETED 46
63 #define GOT_ERR_RANGE 47
65 static const struct got_error {
66 int code;
67 const char *msg;
68 } got_errors[] = {
69 { GOT_ERR_OK, "no error occured?!?" },
70 { GOT_ERR_ERRNO, "see errno" },
71 { GOT_ERR_NOT_GIT_REPO, "no git repository found" },
72 { GOT_ERR_NOT_ABSPATH, "absolute path expected" },
73 { GOT_ERR_BAD_PATH, "bad path" },
74 { GOT_ERR_NOT_REF, "no such reference found" },
75 { GOT_ERR_IO, "input/output error" },
76 { GOT_ERR_EOF, "unexpected end of file" },
77 { GOT_ERR_DECOMPRESSION,"decompression failed" },
78 { GOT_ERR_NO_SPACE, "buffer too small" },
79 { GOT_ERR_BAD_OBJ_HDR, "bad object header" },
80 { GOT_ERR_OBJ_TYPE, "wrong type of object" },
81 { GOT_ERR_BAD_OBJ_DATA, "bad object data" },
82 { GOT_ERR_FILE_OPEN, "could not open file" },
83 { GOT_ERR_BAD_PACKIDX, "bad pack index file" },
84 { GOT_ERR_PACKIDX_CSUM, "pack index file checksum error" },
85 { GOT_ERR_BAD_PACKFILE, "bad pack file" },
86 { GOT_ERR_NO_OBJ, "object not found" },
87 { GOT_ERR_NOT_IMPL, "feature not implemented" },
88 { GOT_ERR_OBJ_NOT_PACKED,"object is not packed" },
89 { GOT_ERR_BAD_DELTA_CHAIN,"bad delta chain" },
90 { GOT_ERR_BAD_DELTA, "bad delta" },
91 { GOT_ERR_COMPRESSION, "compression failed" },
92 { GOT_ERR_BAD_OBJ_ID_STR,"bad object id string" },
93 { GOT_ERR_WORKTREE_EXISTS,"worktree already exists" },
94 { GOT_ERR_WORKTREE_META,"bad worktree meta data" },
95 { GOT_ERR_WORKTREE_VERS,"unsupported worktree format version" },
96 { GOT_ERR_WORKTREE_BUSY,"worktree already locked" },
97 { GOT_ERR_RECURSION, "recursion limit reached" },
98 { GOT_ERR_TIMEOUT, "operation timed out" },
99 { GOT_ERR_INTERRUPT, "operation interrupted" },
100 { GOT_ERR_PRIVSEP_READ, "no data received in imsg" },
101 { GOT_ERR_PRIVSEP_LEN, "unexpected amount of data received in imsg" },
102 { GOT_ERR_PRIVSEP_PIPE, "privsep peer process closed pipe" },
103 { GOT_ERR_PRIVSEP_NO_FD,"privsep file descriptor unavailable" },
104 { GOT_ERR_PRIVSEP_MSG, "unexpected message from unprivileged process" },
105 { GOT_ERR_PRIVSEP_DIED, "unprivileged process died unexpectedly" },
106 { GOT_ERR_PRIVSEP_EXIT, "bad exit code from unprivileged process" },
107 { GOT_ERR_PACK_OFFSET, "bad offset in pack file" },
108 { GOT_ERR_OBJ_EXISTS, "object already exists" },
109 { GOT_ERR_BAD_OBJ_ID, "bad object id" },
110 { GOT_ERR_ITER_NEED_MORE,"more items needed to continue iteration" },
111 { GOT_ERR_ITER_COMPLETED,"iteration completed" },
112 { GOT_ERR_RANGE, "value out of range" },
113 };
115 /*
116 * Get an error object from the above list, for a given error code.
117 * The error message is fixed.
118 */
119 const struct got_error *got_error(int);
121 /*
122 * Get a statically allocated error object with code GOT_ERR_ERRNO
123 * and an error message obtained from strerror(3).
124 */
125 const struct got_error *got_error_from_errno(void);
127 /*
128 * If ferror(3) indicates an error status for the FILE, obtain an error
129 * from got_error_from_errno(). Else, obtain the error via got_error()
130 * with the error code provided in the second argument.
131 */
132 const struct got_error *got_ferror(FILE *, int);