Blame


1 7b19e0f1 2017-11-05 stsp /*
2 0a0a3048 2018-01-10 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 7b19e0f1 2017-11-05 stsp *
4 7b19e0f1 2017-11-05 stsp * Permission to use, copy, modify, and distribute this software for any
5 7b19e0f1 2017-11-05 stsp * purpose with or without fee is hereby granted, provided that the above
6 7b19e0f1 2017-11-05 stsp * copyright notice and this permission notice appear in all copies.
7 7b19e0f1 2017-11-05 stsp *
8 7b19e0f1 2017-11-05 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7b19e0f1 2017-11-05 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7b19e0f1 2017-11-05 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7b19e0f1 2017-11-05 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7b19e0f1 2017-11-05 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7b19e0f1 2017-11-05 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7b19e0f1 2017-11-05 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 7b19e0f1 2017-11-05 stsp */
16 4027f31a 2017-11-04 stsp
17 4027f31a 2017-11-04 stsp /* Error codes */
18 0a585a0d 2018-03-17 stsp #define GOT_ERR_OK 0
19 0a585a0d 2018-03-17 stsp #define GOT_ERR_ERRNO 1
20 a1fd68d8 2018-01-12 stsp #define GOT_ERR_NOT_GIT_REPO 2
21 a1fd68d8 2018-01-12 stsp #define GOT_ERR_NOT_ABSPATH 3
22 a1fd68d8 2018-01-12 stsp #define GOT_ERR_BAD_PATH 4
23 a1fd68d8 2018-01-12 stsp #define GOT_ERR_NOT_REF 5
24 a1fd68d8 2018-01-12 stsp #define GOT_ERR_IO 6
25 a1fd68d8 2018-01-12 stsp #define GOT_ERR_EOF 7
26 a1fd68d8 2018-01-12 stsp #define GOT_ERR_DECOMPRESSION 8
27 a1fd68d8 2018-01-12 stsp #define GOT_ERR_NO_SPACE 9
28 a1fd68d8 2018-01-12 stsp #define GOT_ERR_BAD_OBJ_HDR 10
29 a1fd68d8 2018-01-12 stsp #define GOT_ERR_OBJ_TYPE 11
30 a1fd68d8 2018-01-12 stsp #define GOT_ERR_BAD_OBJ_DATA 12
31 a1fd68d8 2018-01-12 stsp #define GOT_ERR_FILE_OPEN 13
32 a1fd68d8 2018-01-12 stsp #define GOT_ERR_BAD_PACKIDX 14
33 a1fd68d8 2018-01-12 stsp #define GOT_ERR_PACKIDX_CSUM 15
34 a1fd68d8 2018-01-12 stsp #define GOT_ERR_BAD_PACKFILE 16
35 a1fd68d8 2018-01-12 stsp #define GOT_ERR_NO_OBJ 17
36 a487c1d0 2018-01-14 stsp #define GOT_ERR_NOT_IMPL 18
37 3ee5fc21 2018-01-17 stsp #define GOT_ERR_OBJ_NOT_PACKED 19
38 96f5e8b3 2018-01-23 stsp #define GOT_ERR_BAD_DELTA_CHAIN 20
39 885d3e02 2018-01-27 stsp #define GOT_ERR_BAD_DELTA 21
40 885d3e02 2018-01-27 stsp #define GOT_ERR_COMPRESSION 22
41 59ece79d 2018-02-12 stsp #define GOT_ERR_BAD_OBJ_ID_STR 23
42 86c3caaf 2018-03-09 stsp #define GOT_ERR_WORKTREE_EXISTS 26
43 09fe317a 2018-03-11 stsp #define GOT_ERR_WORKTREE_META 27
44 6d9d28c3 2018-03-11 stsp #define GOT_ERR_WORKTREE_VERS 28
45 6d9d28c3 2018-03-11 stsp #define GOT_ERR_WORKTREE_BUSY 29
46 9d31a1d8 2018-03-11 stsp #define GOT_ERR_DIR_OBSTRUCTED 30
47 9d31a1d8 2018-03-11 stsp #define GOT_ERR_FILE_OBSTRUCTED 31
48 5b7e13a7 2018-04-02 stsp #define GOT_ERR_RECURSION 32
49 2178c42e 2018-04-22 stsp #define GOT_ERR_TIMEOUT 33
50 2178c42e 2018-04-22 stsp #define GOT_ERR_INTERRUPT 34
51 2178c42e 2018-04-22 stsp #define GOT_ERR_PRIVSEP_READ 35
52 2178c42e 2018-04-22 stsp #define GOT_ERR_PRIVSEP_LEN 36
53 2178c42e 2018-04-22 stsp #define GOT_ERR_PRIVSEP_PIPE 37
54 2178c42e 2018-04-22 stsp #define GOT_ERR_PRIVSEP_NO_FD 38
55 8c580685 2018-04-22 stsp #define GOT_ERR_PRIVSEP_MSG 39
56 b419fc47 2018-04-26 stsp #define GOT_ERR_PRIVSEP_DIED 40
57 b419fc47 2018-04-26 stsp #define GOT_ERR_PRIVSEP_EXIT 41
58 0c048b15 2018-04-27 stsp #define GOT_ERR_PACK_OFFSET 42
59 54be8251 2018-06-04 stsp #define GOT_ERR_OBJ_EXISTS 43
60 54be8251 2018-06-04 stsp #define GOT_ERR_BAD_OBJ_ID 44
61 372ccdbb 2018-06-10 stsp #define GOT_ERR_ITER_NEED_MORE 45
62 9ba79e04 2018-06-11 stsp #define GOT_ERR_ITER_COMPLETED 46
63 730c718b 2018-06-21 stsp #define GOT_ERR_RANGE 47
64 89817b30 2018-11-11 stsp #define GOT_ERR_EXPECTED 48 /* for use in regress tests only */
65 99437157 2018-11-11 stsp #define GOT_ERR_CANCELLED 49
66 d1451975 2018-11-11 stsp #define GOT_ERR_NO_TREE_ENTRY 50
67 52a74475 2018-12-24 stsp #define GOT_ERR_FILEIDX_SIG 51
68 52a74475 2018-12-24 stsp #define GOT_ERR_FILEIDX_VER 52
69 52a74475 2018-12-24 stsp #define GOT_ERR_FILEIDX_CSUM 53
70 49520a32 2018-12-29 stsp #define GOT_ERR_PATH_PREFIX 54
71 4027f31a 2017-11-04 stsp
72 4027f31a 2017-11-04 stsp static const struct got_error {
73 4027f31a 2017-11-04 stsp int code;
74 4027f31a 2017-11-04 stsp const char *msg;
75 4027f31a 2017-11-04 stsp } got_errors[] = {
76 0a585a0d 2018-03-17 stsp { GOT_ERR_OK, "no error occured?!?" },
77 f334529e 2018-01-12 stsp { GOT_ERR_ERRNO, "see errno" },
78 4027f31a 2017-11-04 stsp { GOT_ERR_NOT_GIT_REPO, "no git repository found" },
79 4027f31a 2017-11-04 stsp { GOT_ERR_NOT_ABSPATH, "absolute path expected" },
80 4027f31a 2017-11-04 stsp { GOT_ERR_BAD_PATH, "bad path" },
81 4027f31a 2017-11-04 stsp { GOT_ERR_NOT_REF, "no such reference found" },
82 ab9a70b2 2017-11-06 stsp { GOT_ERR_IO, "input/output error" },
83 ab9a70b2 2017-11-06 stsp { GOT_ERR_EOF, "unexpected end of file" },
84 ab9a70b2 2017-11-06 stsp { GOT_ERR_DECOMPRESSION,"decompression failed" },
85 ab9a70b2 2017-11-06 stsp { GOT_ERR_NO_SPACE, "buffer too small" },
86 ab9a70b2 2017-11-06 stsp { GOT_ERR_BAD_OBJ_HDR, "bad object header" },
87 d1cda826 2017-11-06 stsp { GOT_ERR_OBJ_TYPE, "wrong type of object" },
88 d1cda826 2017-11-06 stsp { GOT_ERR_BAD_OBJ_DATA, "bad object data" },
89 7d283eee 2017-11-29 stsp { GOT_ERR_FILE_OPEN, "could not open file" },
90 0a0a3048 2018-01-10 stsp { GOT_ERR_BAD_PACKIDX, "bad pack index file" },
91 0ebaf008 2018-01-10 stsp { GOT_ERR_PACKIDX_CSUM, "pack index file checksum error" },
92 a1fd68d8 2018-01-12 stsp { GOT_ERR_BAD_PACKFILE, "bad pack file" },
93 a1fd68d8 2018-01-12 stsp { GOT_ERR_NO_OBJ, "object not found" },
94 a487c1d0 2018-01-14 stsp { GOT_ERR_NOT_IMPL, "feature not implemented" },
95 3ee5fc21 2018-01-17 stsp { GOT_ERR_OBJ_NOT_PACKED,"object is not packed" },
96 96f5e8b3 2018-01-23 stsp { GOT_ERR_BAD_DELTA_CHAIN,"bad delta chain" },
97 59ece79d 2018-02-12 stsp { GOT_ERR_BAD_DELTA, "bad delta" },
98 59ece79d 2018-02-12 stsp { GOT_ERR_COMPRESSION, "compression failed" },
99 59ece79d 2018-02-12 stsp { GOT_ERR_BAD_OBJ_ID_STR,"bad object id string" },
100 86c3caaf 2018-03-09 stsp { GOT_ERR_WORKTREE_EXISTS,"worktree already exists" },
101 09fe317a 2018-03-11 stsp { GOT_ERR_WORKTREE_META,"bad worktree meta data" },
102 6d9d28c3 2018-03-11 stsp { GOT_ERR_WORKTREE_VERS,"unsupported worktree format version" },
103 6d9d28c3 2018-03-11 stsp { GOT_ERR_WORKTREE_BUSY,"worktree already locked" },
104 5b7e13a7 2018-04-02 stsp { GOT_ERR_RECURSION, "recursion limit reached" },
105 2178c42e 2018-04-22 stsp { GOT_ERR_TIMEOUT, "operation timed out" },
106 2178c42e 2018-04-22 stsp { GOT_ERR_INTERRUPT, "operation interrupted" },
107 55afbf19 2018-09-08 stsp { GOT_ERR_PRIVSEP_READ, "no data received in imsg" },
108 55afbf19 2018-09-08 stsp { GOT_ERR_PRIVSEP_LEN, "unexpected amount of data received in imsg" },
109 55afbf19 2018-09-08 stsp { GOT_ERR_PRIVSEP_PIPE, "privsep peer process closed pipe" },
110 55afbf19 2018-09-08 stsp { GOT_ERR_PRIVSEP_NO_FD,"privsep file descriptor unavailable" },
111 4c838a52 2018-12-23 stsp { GOT_ERR_PRIVSEP_MSG, "received unexpected privsep message" },
112 54be8251 2018-06-04 stsp { GOT_ERR_PRIVSEP_DIED, "unprivileged process died unexpectedly" },
113 54be8251 2018-06-04 stsp { GOT_ERR_PRIVSEP_EXIT, "bad exit code from unprivileged process" },
114 54be8251 2018-06-04 stsp { GOT_ERR_PACK_OFFSET, "bad offset in pack file" },
115 54be8251 2018-06-04 stsp { GOT_ERR_OBJ_EXISTS, "object already exists" },
116 54be8251 2018-06-04 stsp { GOT_ERR_BAD_OBJ_ID, "bad object id" },
117 372ccdbb 2018-06-10 stsp { GOT_ERR_ITER_NEED_MORE,"more items needed to continue iteration" },
118 9ba79e04 2018-06-11 stsp { GOT_ERR_ITER_COMPLETED,"iteration completed" },
119 730c718b 2018-06-21 stsp { GOT_ERR_RANGE, "value out of range" },
120 89817b30 2018-11-11 stsp { GOT_ERR_EXPECTED, "expected an error but have no error" },
121 99437157 2018-11-11 stsp { GOT_ERR_CANCELLED, "operation in progress has been cancelled" },
122 d1451975 2018-11-11 stsp { GOT_ERR_NO_TREE_ENTRY,"no such entry found in tree" },
123 52a74475 2018-12-24 stsp { GOT_ERR_FILEIDX_SIG, "bad file index signature" },
124 52a74475 2018-12-24 stsp { GOT_ERR_FILEIDX_VER, "unknown file index format version" },
125 52a74475 2018-12-24 stsp { GOT_ERR_FILEIDX_CSUM, "bad file index checksum" },
126 49520a32 2018-12-29 stsp { GOT_ERR_PATH_PREFIX, "worktree already contains items from a "
127 49520a32 2018-12-29 stsp "different path prefix" },
128 4027f31a 2017-11-04 stsp };
129 4027f31a 2017-11-04 stsp
130 0c60ce5a 2018-04-02 stsp /*
131 0c60ce5a 2018-04-02 stsp * Get an error object from the above list, for a given error code.
132 0c60ce5a 2018-04-02 stsp * The error message is fixed.
133 0c60ce5a 2018-04-02 stsp */
134 0c60ce5a 2018-04-02 stsp const struct got_error *got_error(int);
135 0c60ce5a 2018-04-02 stsp
136 0c60ce5a 2018-04-02 stsp /*
137 91a3d81f 2018-11-11 stsp * Get an error object from the above list, for a given error code.
138 91a3d81f 2018-11-11 stsp * Use the specified error message instead of the default one.
139 91a3d81f 2018-11-11 stsp * Caution: If the message buffer lives in dynamically allocated memory,
140 91a3d81f 2018-11-11 stsp * then this memory likely won't be freed.
141 91a3d81f 2018-11-11 stsp */
142 91a3d81f 2018-11-11 stsp const struct got_error *got_error_msg(int, const char *);
143 91a3d81f 2018-11-11 stsp
144 91a3d81f 2018-11-11 stsp /*
145 0c60ce5a 2018-04-02 stsp * Get a statically allocated error object with code GOT_ERR_ERRNO
146 0c60ce5a 2018-04-02 stsp * and an error message obtained from strerror(3).
147 0c60ce5a 2018-04-02 stsp */
148 25783624 2018-03-12 stsp const struct got_error *got_error_from_errno(void);
149 0c60ce5a 2018-04-02 stsp
150 0c60ce5a 2018-04-02 stsp /*
151 1a76625f 2018-10-22 stsp * Set errno to the specified error code and return a statically
152 1a76625f 2018-10-22 stsp * allocated error object with code GOT_ERR_ERRNO and an error
153 1a76625f 2018-10-22 stsp * message obtained from strerror(3).
154 1a76625f 2018-10-22 stsp */
155 1a76625f 2018-10-22 stsp const struct got_error *got_error_set_errno(int);
156 1a76625f 2018-10-22 stsp
157 1a76625f 2018-10-22 stsp /*
158 0c60ce5a 2018-04-02 stsp * If ferror(3) indicates an error status for the FILE, obtain an error
159 0c60ce5a 2018-04-02 stsp * from got_error_from_errno(). Else, obtain the error via got_error()
160 0c60ce5a 2018-04-02 stsp * with the error code provided in the second argument.
161 0c60ce5a 2018-04-02 stsp */
162 8251fdbc 2018-01-12 stsp const struct got_error *got_ferror(FILE *, int);
163 91a3d81f 2018-11-11 stsp
164 91a3d81f 2018-11-11 stsp /*
165 91a3d81f 2018-11-11 stsp * Obtain an error with code GOT_ERR_NO_OBJ and an error message which
166 91a3d81f 2018-11-11 stsp * contains the specified object ID. The message buffer is statically
167 91a3d81f 2018-11-11 stsp * allocated; future invocations of this function will overwrite the
168 91a3d81f 2018-11-11 stsp * message set during earlier invocations.
169 91a3d81f 2018-11-11 stsp */
170 91a3d81f 2018-11-11 stsp struct got_object_id; /* forward declaration */
171 91a3d81f 2018-11-11 stsp const struct got_error *got_error_no_obj(struct got_object_id *);