Blob


1 /*
2 * Copyright (c) 2018, 2019 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 /* 13 is currently free for re-use */
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
64 #define GOT_ERR_EXPECTED 48 /* for use in regress tests only */
65 #define GOT_ERR_CANCELLED 49
66 #define GOT_ERR_NO_TREE_ENTRY 50
67 #define GOT_ERR_FILEIDX_SIG 51
68 #define GOT_ERR_FILEIDX_VER 52
69 #define GOT_ERR_FILEIDX_CSUM 53
70 #define GOT_ERR_PATH_PREFIX 54
71 #define GOT_ERR_ANCESTRY 55
72 #define GOT_ERR_FILEIDX_BAD 56
73 #define GOT_ERR_BAD_REF_DATA 57
74 #define GOT_ERR_TREE_DUP_ENTRY 58
75 #define GOT_ERR_DIR_DUP_ENTRY 59
76 #define GOT_ERR_NOT_WORKTREE 60
77 #define GOT_ERR_UUID_VERSION 61
78 #define GOT_ERR_UUID_INVALID 62
79 #define GOT_ERR_UUID 63
80 #define GOT_ERR_LOCKFILE_TIMEOUT 64
81 #define GOT_ERR_BAD_REF_NAME 65
82 #define GOT_ERR_WORKTREE_REPO 66
83 #define GOT_ERR_FILE_MODIFIED 67
84 #define GOT_ERR_FILE_STATUS 68
85 #define GOT_ERR_COMMIT_CONFLICT 69
86 #define GOT_ERR_BAD_REF_TYPE 70
87 #define GOT_ERR_COMMIT_NO_AUTHOR 71
88 #define GOT_ERR_COMMIT_HEAD_CHANGED 72
89 #define GOT_ERR_COMMIT_OUT_OF_DATE 73
91 static const struct got_error {
92 int code;
93 const char *msg;
94 } got_errors[] = {
95 { GOT_ERR_OK, "no error occured?!?" },
96 { GOT_ERR_ERRNO, "see errno" },
97 { GOT_ERR_NOT_GIT_REPO, "no git repository found" },
98 { GOT_ERR_NOT_ABSPATH, "absolute path expected" },
99 { GOT_ERR_BAD_PATH, "bad path" },
100 { GOT_ERR_NOT_REF, "no such reference found" },
101 { GOT_ERR_IO, "input/output error" },
102 { GOT_ERR_EOF, "unexpected end of file" },
103 { GOT_ERR_DECOMPRESSION,"decompression failed" },
104 { GOT_ERR_NO_SPACE, "buffer too small" },
105 { GOT_ERR_BAD_OBJ_HDR, "bad object header" },
106 { GOT_ERR_OBJ_TYPE, "wrong type of object" },
107 { GOT_ERR_BAD_OBJ_DATA, "bad object data" },
108 { 13, "unused error code" },
109 { GOT_ERR_BAD_PACKIDX, "bad pack index file" },
110 { GOT_ERR_PACKIDX_CSUM, "pack index file checksum error" },
111 { GOT_ERR_BAD_PACKFILE, "bad pack file" },
112 { GOT_ERR_NO_OBJ, "object not found" },
113 { GOT_ERR_NOT_IMPL, "feature not implemented" },
114 { GOT_ERR_OBJ_NOT_PACKED,"object is not packed" },
115 { GOT_ERR_BAD_DELTA_CHAIN,"bad delta chain" },
116 { GOT_ERR_BAD_DELTA, "bad delta" },
117 { GOT_ERR_COMPRESSION, "compression failed" },
118 { GOT_ERR_BAD_OBJ_ID_STR,"bad object id string" },
119 { GOT_ERR_WORKTREE_EXISTS,"worktree already exists" },
120 { GOT_ERR_WORKTREE_META,"bad worktree meta data" },
121 { GOT_ERR_WORKTREE_VERS,"unsupported worktree format version" },
122 { GOT_ERR_WORKTREE_BUSY,"worktree already locked" },
123 { GOT_ERR_FILE_OBSTRUCTED,"file is obstructed" },
124 { GOT_ERR_RECURSION, "recursion limit reached" },
125 { GOT_ERR_TIMEOUT, "operation timed out" },
126 { GOT_ERR_INTERRUPT, "operation interrupted" },
127 { GOT_ERR_PRIVSEP_READ, "no data received in imsg" },
128 { GOT_ERR_PRIVSEP_LEN, "unexpected amount of data received in imsg" },
129 { GOT_ERR_PRIVSEP_PIPE, "privsep peer process closed pipe" },
130 { GOT_ERR_PRIVSEP_NO_FD,"privsep file descriptor unavailable" },
131 { GOT_ERR_PRIVSEP_MSG, "received unexpected privsep message" },
132 { GOT_ERR_PRIVSEP_DIED, "unprivileged process died unexpectedly" },
133 { GOT_ERR_PRIVSEP_EXIT, "bad exit code from unprivileged process" },
134 { GOT_ERR_PACK_OFFSET, "bad offset in pack file" },
135 { GOT_ERR_OBJ_EXISTS, "object already exists" },
136 { GOT_ERR_BAD_OBJ_ID, "bad object id" },
137 { GOT_ERR_ITER_NEED_MORE,"more items needed to continue iteration" },
138 { GOT_ERR_ITER_COMPLETED,"iteration completed" },
139 { GOT_ERR_RANGE, "value out of range" },
140 { GOT_ERR_EXPECTED, "expected an error but have no error" },
141 { GOT_ERR_CANCELLED, "operation in progress has been cancelled" },
142 { GOT_ERR_NO_TREE_ENTRY,"no such entry found in tree" },
143 { GOT_ERR_FILEIDX_SIG, "bad file index signature" },
144 { GOT_ERR_FILEIDX_VER, "unknown file index format version" },
145 { GOT_ERR_FILEIDX_CSUM, "bad file index checksum" },
146 { GOT_ERR_PATH_PREFIX, "worktree already contains items from a "
147 "different path prefix" },
148 { GOT_ERR_ANCESTRY, "specified commit does not share ancestry with "
149 "the current branch" },
150 { GOT_ERR_FILEIDX_BAD, "file index is corrupt" },
151 { GOT_ERR_BAD_REF_DATA, "could not parse reference data" },
152 { GOT_ERR_TREE_DUP_ENTRY,"duplicate entry in tree object" },
153 { GOT_ERR_DIR_DUP_ENTRY,"duplicate entry in directory" },
154 { GOT_ERR_NOT_WORKTREE, "no got work tree found" },
155 { GOT_ERR_UUID_VERSION, "bad uuid version" },
156 { GOT_ERR_UUID_INVALID, "uuid invalid" },
157 { GOT_ERR_UUID, "uuid error" },
158 { GOT_ERR_LOCKFILE_TIMEOUT,"lockfile timeout" },
159 { GOT_ERR_BAD_REF_NAME, "bad reference name" },
160 { GOT_ERR_WORKTREE_REPO,"cannot create worktree inside a git repository" },
161 { GOT_ERR_FILE_MODIFIED,"file contains modifications" },
162 { GOT_ERR_FILE_STATUS, "file has unexpected status" },
163 { GOT_ERR_COMMIT_CONFLICT,"cannot commit file in conflicted status" },
164 { GOT_ERR_BAD_REF_TYPE, "bad reference type" },
165 { GOT_ERR_COMMIT_NO_AUTHOR,"GOT_AUTHOR environment variable is not set" },
166 { GOT_ERR_COMMIT_HEAD_CHANGED, "branch head in repository has changed "
167 "while commit was in progress" },
168 { GOT_ERR_COMMIT_OUT_OF_DATE, "work tree must be updated before these "
169 "changes can be committed" },
170 };
172 /*
173 * Get an error object from the above list, for a given error code.
174 * The error message is fixed.
175 */
176 const struct got_error *got_error(int);
178 /*
179 * Get an error object from the above list, for a given error code.
180 * Use the specified error message instead of the default one.
181 * Caution: If the message buffer lives in dynamically allocated memory,
182 * then this memory likely won't be freed.
183 */
184 const struct got_error *got_error_msg(int, const char *);
186 /*
187 * Get a statically allocated error object with code GOT_ERR_ERRNO
188 * and an error message obtained from strerror(3).
189 */
190 const struct got_error *got_error_from_errno(void);
192 /*
193 * Set errno to the specified error code and return a statically
194 * allocated error object with code GOT_ERR_ERRNO and an error
195 * message obtained from strerror(3).
196 */
197 const struct got_error *got_error_set_errno(int);
199 /*
200 * If ferror(3) indicates an error status for the FILE, obtain an error
201 * from got_error_from_errno(). Else, obtain the error via got_error()
202 * with the error code provided in the second argument.
203 */
204 const struct got_error *got_ferror(FILE *, int);
206 /*
207 * Obtain an error with code GOT_ERR_NO_OBJ and an error message which
208 * contains the specified object ID. The message buffer is statically
209 * allocated; future invocations of this function will overwrite the
210 * message set during earlier invocations.
211 */
212 struct got_object_id; /* forward declaration */
213 const struct got_error *got_error_no_obj(struct got_object_id *);
215 /*
216 * Obtain an error with code GOT_ERR_NOT_REF and an error message which
217 * contains the specified reference name. The message buffer is statically
218 * allocated; future invocations of this function will overwrite the
219 * message set during earlier invocations.
220 */
221 const struct got_error *got_error_not_ref(const char *);
223 /* Return an error based on a uuid(3) status code. */
224 const struct got_error *got_error_uuid(uint32_t);