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 #define GOT_ERR_AMBIGUOUS_ID 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
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
90 #define GOT_ERR_COMMIT_MSG_EMPTY 74
91 #define GOT_ERR_DIR_NOT_EMPTY 75
92 #define GOT_ERR_COMMIT_NO_CHANGES 76
93 #define GOT_ERR_BRANCH_MOVED 77
94 #define GOT_ERR_OBJ_TOO_LARGE 78
95 #define GOT_ERR_SAME_BRANCH 79
96 #define GOT_ERR_ROOT_COMMIT 80
97 #define GOT_ERR_MIXED_COMMITS 81
98 #define GOT_ERR_CONFLICTS 82
99 #define GOT_ERR_BRANCH_EXISTS 83
100 #define GOT_ERR_MODIFIED 84
101 #define GOT_ERR_NOT_REBASING 85
102 #define GOT_ERR_EMPTY_REBASE 86
103 #define GOT_ERR_REBASE_COMMITID 87
104 #define GOT_ERR_REBASING 88
105 #define GOT_ERR_REBASE_PATH 89
106 #define GOT_ERR_NOT_HISTEDIT 90
107 #define GOT_ERR_EMPTY_HISTEDIT 91
108 #define GOT_ERR_NO_HISTEDIT_CMD 92
109 #define GOT_ERR_HISTEDIT_SYNTAX 93
110 #define GOT_ERR_HISTEDIT_CANCEL 94
111 #define GOT_ERR_HISTEDIT_COMMITID 95
112 #define GOT_ERR_HISTEDIT_BUSY 96
113 #define GOT_ERR_HISTEDIT_CMD 97
114 #define GOT_ERR_HISTEDIT_PATH 98
115 #define GOT_ERR_NO_MERGED_PATHS 99
116 #define GOT_ERR_COMMIT_BRANCH 100
117 #define GOT_ERR_FILE_STAGED 101
118 #define GOT_ERR_STAGE_NO_CHANGE 102
119 #define GOT_ERR_STAGE_CONFLICT 103
120 #define GOT_ERR_STAGE_OUT_OF_DATE 104
121 #define GOT_ERR_FILE_NOT_STAGED 105
122 #define GOT_ERR_STAGED_PATHS 106
123 #define GOT_ERR_PATCH_CHOICE 107
124 #define GOT_ERR_COMMIT_NO_EMAIL 108
125 #define GOT_ERR_TAG_EXISTS 109
126 #define GOT_ERR_GIT_REPO_FORMAT 110
127 #define GOT_ERR_REBASE_REQUIRED 111
129 static const struct got_error {
130 int code;
131 const char *msg;
132 } got_errors[] = {
133 { GOT_ERR_OK, "no error occured?!?" },
134 { GOT_ERR_ERRNO, "see errno" },
135 { GOT_ERR_NOT_GIT_REPO, "no git repository found" },
136 { GOT_ERR_NOT_ABSPATH, "absolute path expected" },
137 { GOT_ERR_BAD_PATH, "bad path" },
138 { GOT_ERR_NOT_REF, "no such reference found" },
139 { GOT_ERR_IO, "input/output error" },
140 { GOT_ERR_EOF, "unexpected end of file" },
141 { GOT_ERR_DECOMPRESSION,"decompression failed" },
142 { GOT_ERR_NO_SPACE, "buffer too small" },
143 { GOT_ERR_BAD_OBJ_HDR, "bad object header" },
144 { GOT_ERR_OBJ_TYPE, "wrong type of object" },
145 { GOT_ERR_BAD_OBJ_DATA, "bad object data" },
146 { GOT_ERR_AMBIGUOUS_ID, "ambiguous object ID" },
147 { GOT_ERR_BAD_PACKIDX, "bad pack index file" },
148 { GOT_ERR_PACKIDX_CSUM, "pack index file checksum error" },
149 { GOT_ERR_BAD_PACKFILE, "bad pack file" },
150 { GOT_ERR_NO_OBJ, "object not found" },
151 { GOT_ERR_NOT_IMPL, "feature not implemented" },
152 { GOT_ERR_OBJ_NOT_PACKED,"object is not packed" },
153 { GOT_ERR_BAD_DELTA_CHAIN,"bad delta chain" },
154 { GOT_ERR_BAD_DELTA, "bad delta" },
155 { GOT_ERR_COMPRESSION, "compression failed" },
156 { GOT_ERR_BAD_OBJ_ID_STR,"bad object id string" },
157 { GOT_ERR_WORKTREE_EXISTS,"worktree already exists" },
158 { GOT_ERR_WORKTREE_META,"bad worktree meta data" },
159 { GOT_ERR_WORKTREE_VERS,"unsupported worktree format version" },
160 { GOT_ERR_WORKTREE_BUSY,"worktree already locked" },
161 { GOT_ERR_FILE_OBSTRUCTED,"file is obstructed" },
162 { GOT_ERR_RECURSION, "recursion limit reached" },
163 { GOT_ERR_TIMEOUT, "operation timed out" },
164 { GOT_ERR_INTERRUPT, "operation interrupted" },
165 { GOT_ERR_PRIVSEP_READ, "no data received in imsg" },
166 { GOT_ERR_PRIVSEP_LEN, "unexpected amount of data received in imsg" },
167 { GOT_ERR_PRIVSEP_PIPE, "privsep peer process closed pipe" },
168 { GOT_ERR_PRIVSEP_NO_FD,"privsep file descriptor unavailable" },
169 { GOT_ERR_PRIVSEP_MSG, "received unexpected privsep message" },
170 { GOT_ERR_PRIVSEP_DIED, "unprivileged process died unexpectedly" },
171 { GOT_ERR_PRIVSEP_EXIT, "bad exit code from unprivileged process" },
172 { GOT_ERR_PACK_OFFSET, "bad offset in pack file" },
173 { GOT_ERR_OBJ_EXISTS, "object already exists" },
174 { GOT_ERR_BAD_OBJ_ID, "bad object id" },
175 { GOT_ERR_ITER_NEED_MORE,"more items needed to continue iteration" },
176 { GOT_ERR_ITER_COMPLETED,"iteration completed" },
177 { GOT_ERR_RANGE, "value out of range" },
178 { GOT_ERR_EXPECTED, "expected an error but have no error" },
179 { GOT_ERR_CANCELLED, "operation in progress has been cancelled" },
180 { GOT_ERR_NO_TREE_ENTRY,"no such entry found in tree" },
181 { GOT_ERR_FILEIDX_SIG, "bad file index signature" },
182 { GOT_ERR_FILEIDX_VER, "unknown file index format version" },
183 { GOT_ERR_FILEIDX_CSUM, "bad file index checksum" },
184 { GOT_ERR_PATH_PREFIX, "worktree already contains items from a "
185 "different path prefix" },
186 { GOT_ERR_ANCESTRY, "target commit is on a different branch" },
187 { GOT_ERR_FILEIDX_BAD, "file index is corrupt" },
188 { GOT_ERR_BAD_REF_DATA, "could not parse reference data" },
189 { GOT_ERR_TREE_DUP_ENTRY,"duplicate entry in tree object" },
190 { GOT_ERR_DIR_DUP_ENTRY,"duplicate entry in directory" },
191 { GOT_ERR_NOT_WORKTREE, "no got work tree found" },
192 { GOT_ERR_UUID_VERSION, "bad uuid version" },
193 { GOT_ERR_UUID_INVALID, "uuid invalid" },
194 { GOT_ERR_UUID, "uuid error" },
195 { GOT_ERR_LOCKFILE_TIMEOUT,"lockfile timeout" },
196 { GOT_ERR_BAD_REF_NAME, "bad reference name" },
197 { GOT_ERR_WORKTREE_REPO,"cannot create worktree inside a git repository" },
198 { GOT_ERR_FILE_MODIFIED,"file contains modifications" },
199 { GOT_ERR_FILE_STATUS, "file has unexpected status" },
200 { GOT_ERR_COMMIT_CONFLICT,"cannot commit file in conflicted status" },
201 { GOT_ERR_BAD_REF_TYPE, "bad reference type" },
202 { GOT_ERR_COMMIT_NO_AUTHOR,"GOT_AUTHOR environment variable is not set" },
203 { GOT_ERR_COMMIT_HEAD_CHANGED, "branch head in repository has changed "
204 "while commit was in progress" },
205 { GOT_ERR_COMMIT_OUT_OF_DATE, "work tree must be updated before these "
206 "changes can be committed" },
207 { GOT_ERR_COMMIT_MSG_EMPTY, "commit message cannot be empty" },
208 { GOT_ERR_DIR_NOT_EMPTY, "directory exists and is not empty" },
209 { GOT_ERR_COMMIT_NO_CHANGES, "no changes to commit" },
210 { GOT_ERR_BRANCH_MOVED, "work tree's head reference now points to a "
211 "different branch; new head reference and/or update -b required" },
212 { GOT_ERR_OBJ_TOO_LARGE, "object too large" },
213 { GOT_ERR_SAME_BRANCH, "commit is already contained in this branch" },
214 { GOT_ERR_ROOT_COMMIT, "specified commit has no parent commit" },
215 { GOT_ERR_MIXED_COMMITS,"work tree contains files from multiple "
216 "base commits; the entire work tree must be updated first" },
217 { GOT_ERR_CONFLICTS, "work tree contains conflicted files; these "
218 "conflicts must be resolved first" },
219 { GOT_ERR_BRANCH_EXISTS,"specified branch already exists" },
220 { GOT_ERR_MODIFIED, "work tree contains local changes; these "
221 "changes must be committed or reverted first" },
222 { GOT_ERR_NOT_REBASING, "rebase operation not in progress" },
223 { GOT_ERR_EMPTY_REBASE, "no commits to rebase" },
224 { GOT_ERR_REBASE_COMMITID,"rebase commit ID mismatch" },
225 { GOT_ERR_REBASING, "a rebase operation is in progress in this "
226 "work tree and must be continued or aborted first" },
227 { GOT_ERR_REBASE_PATH, "cannot rebase branch which contains "
228 "changes outside of this work tree's path prefix" },
229 { GOT_ERR_NOT_HISTEDIT, "histedit operation not in progress" },
230 { GOT_ERR_EMPTY_HISTEDIT,"no commits to edit; perhaps the work tree "
231 "must be updated to an older commit first" },
232 { GOT_ERR_NO_HISTEDIT_CMD,"no histedit commands provided" },
233 { GOT_ERR_HISTEDIT_SYNTAX,"syntax error in histedit command list" },
234 { GOT_ERR_HISTEDIT_CANCEL,"histedit operation cancelled" },
235 { GOT_ERR_HISTEDIT_COMMITID,"histedit commit ID mismatch" },
236 { GOT_ERR_HISTEDIT_BUSY,"histedit operation is in progress in this "
237 "work tree and must be continued or aborted first" },
238 { GOT_ERR_HISTEDIT_CMD, "bad histedit command" },
239 { GOT_ERR_HISTEDIT_PATH, "cannot edit branch history which contains "
240 "changes outside of this work tree's path prefix" },
241 { GOT_ERR_NO_MERGED_PATHS, "empty list of merged paths" },
242 { GOT_ERR_COMMIT_BRANCH, "will not commit to a branch outside the "
243 "\"refs/heads/\" reference namespace" },
244 { GOT_ERR_FILE_STAGED, "file is staged" },
245 { GOT_ERR_STAGE_NO_CHANGE, "no changes to stage" },
246 { GOT_ERR_STAGE_CONFLICT, "cannot stage file in conflicted status" },
247 { GOT_ERR_STAGE_OUT_OF_DATE, "work tree must be updated before "
248 "changes can be staged" },
249 { GOT_ERR_FILE_NOT_STAGED, "file is not staged" },
250 { GOT_ERR_STAGED_PATHS, "work tree contains files with staged "
251 "changes; these changes must be committed or unstaged first" },
252 { GOT_ERR_PATCH_CHOICE, "invalid patch choice" },
253 { GOT_ERR_COMMIT_NO_EMAIL,"GOT_AUTHOR environment variable contains "
254 "no email address; an email address is required for compatibility "
255 "with Git" },
256 { GOT_ERR_TAG_EXISTS,"specified tag already exists" },
257 { GOT_ERR_GIT_REPO_FORMAT,"unknown git repository format version" },
258 { GOT_ERR_REBASE_REQUIRED,"specified branch must be rebased first" },
259 };
261 /*
262 * Get an error object from the above list, for a given error code.
263 * The error message is fixed.
264 */
265 const struct got_error *got_error(int);
267 /*
268 * Get an error object from the above list, for a given error code.
269 * Use the specified error message instead of the default one.
270 * Caution: If the message buffer lives in dynamically allocated memory,
271 * then this memory likely won't be freed.
272 */
273 const struct got_error *got_error_msg(int, const char *);
275 /*
276 * Get a statically allocated error object with code GOT_ERR_ERRNO
277 * and an error message obtained from strerror(3), prefixed with a
278 * string.
279 */
280 const struct got_error *got_error_from_errno(const char *);
282 /*
283 * Get a statically allocated error object with code GOT_ERR_ERRNO
284 * and an error message obtained from strerror(3), prefixed with two
285 * strings.
286 */
287 const struct got_error *got_error_from_errno2(const char *, const char *);
289 /*
290 * Get a statically allocated error object with code GOT_ERR_ERRNO
291 * and an error message obtained from strerror(3), prefixed with three
292 * strings.
293 */
294 const struct got_error *got_error_from_errno3(const char *, const char *,
295 const char *);
297 /*
298 * Set errno to the specified error code and return a statically
299 * allocated error object with code GOT_ERR_ERRNO and an error
300 * message obtained from strerror(3), optionally prefixed with a
301 * string.
302 */
303 const struct got_error *got_error_set_errno(int, const char *);
305 /*
306 * If ferror(3) indicates an error status for the FILE, obtain an error
307 * from got_error_from_errno(). Else, obtain the error via got_error()
308 * with the error code provided in the second argument.
309 */
310 const struct got_error *got_ferror(FILE *, int);
312 /*
313 * Obtain an error with code GOT_ERR_NO_OBJ and an error message which
314 * contains the specified object ID. The message buffer is statically
315 * allocated; future invocations of this function will overwrite the
316 * message set during earlier invocations.
317 */
318 struct got_object_id; /* forward declaration */
319 const struct got_error *got_error_no_obj(struct got_object_id *);
321 /*
322 * Obtain an error with code GOT_ERR_NOT_REF and an error message which
323 * contains the specified reference name. The message buffer is statically
324 * allocated; future invocations of this function will overwrite the
325 * message set during earlier invocations.
326 */
327 const struct got_error *got_error_not_ref(const char *);
329 /* Return an error based on a uuid(3) status code. */
330 const struct got_error *got_error_uuid(uint32_t, const char *);
332 /* Return an error with a path prefixed to the error message. */
333 const struct got_error *got_error_path(const char *, int);