1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 4 * This file is part of libgit2, distributed under the GNU GPL v2 with 5 * a Linking Exception. For full terms see the included COPYING file. 6 */ 7 module libgit2_d.errors; 8 9 10 /** 11 * @file git2/errors.h 12 * @brief Git error handling routines and variables 13 * @ingroup Git 14 * @{ 15 */ 16 extern (C): 17 nothrow @nogc: 18 public: 19 20 /** 21 * Generic return codes 22 */ 23 enum git_error_code 24 { 25 /** 26 * No error 27 */ 28 GIT_OK = 0, 29 30 /** 31 * Generic error 32 */ 33 GIT_ERROR = -1, 34 35 /** 36 * Requested object could not be found 37 */ 38 GIT_ENOTFOUND = -3, 39 40 /** 41 * Object exists preventing operation 42 */ 43 GIT_EEXISTS = -4, 44 45 /** 46 * More than one object matches 47 */ 48 GIT_EAMBIGUOUS = -5, 49 50 /** 51 * Output buffer too short to hold data 52 */ 53 GIT_EBUFS = -6, 54 55 /** 56 * GIT_EUSER is a special error that is never generated by libgit2 57 * code. You can return it from a callback (e.g to stop an iteration) 58 * to know that it was generated by the callback and not by libgit2. 59 */ 60 GIT_EUSER = -7, 61 62 /** 63 * Operation not allowed on bare repository 64 */ 65 GIT_EBAREREPO = -8, 66 67 /** 68 * HEAD refers to branch with no commits 69 */ 70 GIT_EUNBORNBRANCH = -9, 71 72 /** 73 * Merge in progress prevented operation 74 */ 75 GIT_EUNMERGED = -10, 76 77 /** 78 * Reference was not fast-forwardable 79 */ 80 GIT_ENONFASTFORWARD = -11, 81 82 /** 83 * Name/ref spec was not in a valid format 84 */ 85 GIT_EINVALIDSPEC = -12, 86 87 /** 88 * Checkout conflicts prevented operation 89 */ 90 GIT_ECONFLICT = -13, 91 92 /** 93 * Lock file prevented operation 94 */ 95 GIT_ELOCKED = -14, 96 97 /** 98 * Reference value does not match expected 99 */ 100 GIT_EMODIFIED = -15, 101 102 /** 103 * Authentication error 104 */ 105 GIT_EAUTH = -16, 106 107 /** 108 * Server certificate is invalid 109 */ 110 GIT_ECERTIFICATE = -17, 111 112 /** 113 * Patch/merge has already been applied 114 */ 115 GIT_EAPPLIED = -18, 116 117 /** 118 * The requested peel operation is not possible 119 */ 120 GIT_EPEEL = -19, 121 122 /** 123 * Unexpected EOF 124 */ 125 GIT_EEOF = -20, 126 127 /** 128 * Invalid operation or input 129 */ 130 GIT_EINVALID = -21, 131 132 /** 133 * Uncommitted changes in index prevented operation 134 */ 135 GIT_EUNCOMMITTED = -22, 136 137 /** 138 * The operation is not valid for a directory 139 */ 140 GIT_EDIRECTORY = -23, 141 142 /** 143 * A merge conflict exists and cannot continue 144 */ 145 GIT_EMERGECONFLICT = -24, 146 147 /** 148 * A user-configured callback refused to act 149 */ 150 GIT_PASSTHROUGH = -30, 151 152 /** 153 * Signals end of iteration with iterator 154 */ 155 GIT_ITEROVER = -31, 156 157 /** 158 * Internal only 159 */ 160 GIT_RETRY = -32, 161 162 /** 163 * Hashsum mismatch in object 164 */ 165 GIT_EMISMATCH = -33, 166 167 /** 168 * Unsaved changes in the index would be overwritten 169 */ 170 GIT_EINDEXDIRTY = -34, 171 172 /** 173 * Patch application failed 174 */ 175 GIT_EAPPLYFAIL = -35, 176 } 177 178 //Declaration name in C language 179 enum 180 { 181 GIT_OK = .git_error_code.GIT_OK, 182 GIT_ERROR = .git_error_code.GIT_ERROR, 183 GIT_ENOTFOUND = .git_error_code.GIT_ENOTFOUND, 184 GIT_EEXISTS = .git_error_code.GIT_EEXISTS, 185 GIT_EAMBIGUOUS = .git_error_code.GIT_EAMBIGUOUS, 186 GIT_EBUFS = .git_error_code.GIT_EBUFS, 187 GIT_EUSER = .git_error_code.GIT_EUSER, 188 GIT_EBAREREPO = .git_error_code.GIT_EBAREREPO, 189 GIT_EUNBORNBRANCH = .git_error_code.GIT_EUNBORNBRANCH, 190 GIT_EUNMERGED = .git_error_code.GIT_EUNMERGED, 191 GIT_ENONFASTFORWARD = .git_error_code.GIT_ENONFASTFORWARD, 192 GIT_EINVALIDSPEC = .git_error_code.GIT_EINVALIDSPEC, 193 GIT_ECONFLICT = .git_error_code.GIT_ECONFLICT, 194 GIT_ELOCKED = .git_error_code.GIT_ELOCKED, 195 GIT_EMODIFIED = .git_error_code.GIT_EMODIFIED, 196 GIT_EAUTH = .git_error_code.GIT_EAUTH, 197 GIT_ECERTIFICATE = .git_error_code.GIT_ECERTIFICATE, 198 GIT_EAPPLIED = .git_error_code.GIT_EAPPLIED, 199 GIT_EPEEL = .git_error_code.GIT_EPEEL, 200 GIT_EEOF = .git_error_code.GIT_EEOF, 201 GIT_EINVALID = .git_error_code.GIT_EINVALID, 202 GIT_EUNCOMMITTED = .git_error_code.GIT_EUNCOMMITTED, 203 GIT_EDIRECTORY = .git_error_code.GIT_EDIRECTORY, 204 GIT_EMERGECONFLICT = .git_error_code.GIT_EMERGECONFLICT, 205 GIT_PASSTHROUGH = .git_error_code.GIT_PASSTHROUGH, 206 GIT_ITEROVER = .git_error_code.GIT_ITEROVER, 207 GIT_RETRY = .git_error_code.GIT_RETRY, 208 GIT_EMISMATCH = .git_error_code.GIT_EMISMATCH, 209 GIT_EINDEXDIRTY = .git_error_code.GIT_EINDEXDIRTY, 210 GIT_EAPPLYFAIL = .git_error_code.GIT_EAPPLYFAIL, 211 } 212 213 /** 214 * Structure to store extra details of the last error that occurred. 215 * 216 * This is kept on a per-thread basis if GIT_THREADS was defined when the 217 * library was build, otherwise one is kept globally for the library 218 */ 219 struct git_error 220 { 221 char* message; 222 int klass; 223 } 224 225 /** 226 * Error classes 227 */ 228 enum git_error_t 229 { 230 GIT_ERROR_NONE = 0, 231 GIT_ERROR_NOMEMORY, 232 GIT_ERROR_OS, 233 GIT_ERROR_INVALID, 234 GIT_ERROR_REFERENCE, 235 GIT_ERROR_ZLIB, 236 GIT_ERROR_REPOSITORY, 237 GIT_ERROR_CONFIG, 238 GIT_ERROR_REGEX, 239 GIT_ERROR_ODB, 240 GIT_ERROR_INDEX, 241 GIT_ERROR_OBJECT, 242 GIT_ERROR_NET, 243 GIT_ERROR_TAG, 244 GIT_ERROR_TREE, 245 GIT_ERROR_INDEXER, 246 GIT_ERROR_SSL, 247 GIT_ERROR_SUBMODULE, 248 GIT_ERROR_THREAD, 249 GIT_ERROR_STASH, 250 GIT_ERROR_CHECKOUT, 251 GIT_ERROR_FETCHHEAD, 252 GIT_ERROR_MERGE, 253 GIT_ERROR_SSH, 254 GIT_ERROR_FILTER, 255 GIT_ERROR_REVERT, 256 GIT_ERROR_CALLBACK, 257 GIT_ERROR_CHERRYPICK, 258 GIT_ERROR_DESCRIBE, 259 GIT_ERROR_REBASE, 260 GIT_ERROR_FILESYSTEM, 261 GIT_ERROR_PATCH, 262 GIT_ERROR_WORKTREE, 263 GIT_ERROR_SHA1, 264 GIT_ERROR_HTTP, 265 GIT_ERROR_INTERNAL, 266 } 267 268 //Declaration name in C language 269 enum 270 { 271 GIT_ERROR_NONE = .git_error_t.GIT_ERROR_NONE, 272 GIT_ERROR_NOMEMORY = .git_error_t.GIT_ERROR_NOMEMORY, 273 GIT_ERROR_OS = .git_error_t.GIT_ERROR_OS, 274 GIT_ERROR_INVALID = .git_error_t.GIT_ERROR_INVALID, 275 GIT_ERROR_REFERENCE = .git_error_t.GIT_ERROR_REFERENCE, 276 GIT_ERROR_ZLIB = .git_error_t.GIT_ERROR_ZLIB, 277 GIT_ERROR_REPOSITORY = .git_error_t.GIT_ERROR_REPOSITORY, 278 GIT_ERROR_CONFIG = .git_error_t.GIT_ERROR_CONFIG, 279 GIT_ERROR_REGEX = .git_error_t.GIT_ERROR_REGEX, 280 GIT_ERROR_ODB = .git_error_t.GIT_ERROR_ODB, 281 GIT_ERROR_INDEX = .git_error_t.GIT_ERROR_INDEX, 282 GIT_ERROR_OBJECT = .git_error_t.GIT_ERROR_OBJECT, 283 GIT_ERROR_NET = .git_error_t.GIT_ERROR_NET, 284 GIT_ERROR_TAG = .git_error_t.GIT_ERROR_TAG, 285 GIT_ERROR_TREE = .git_error_t.GIT_ERROR_TREE, 286 GIT_ERROR_INDEXER = .git_error_t.GIT_ERROR_INDEXER, 287 GIT_ERROR_SSL = .git_error_t.GIT_ERROR_SSL, 288 GIT_ERROR_SUBMODULE = .git_error_t.GIT_ERROR_SUBMODULE, 289 GIT_ERROR_THREAD = .git_error_t.GIT_ERROR_THREAD, 290 GIT_ERROR_STASH = .git_error_t.GIT_ERROR_STASH, 291 GIT_ERROR_CHECKOUT = .git_error_t.GIT_ERROR_CHECKOUT, 292 GIT_ERROR_FETCHHEAD = .git_error_t.GIT_ERROR_FETCHHEAD, 293 GIT_ERROR_MERGE = .git_error_t.GIT_ERROR_MERGE, 294 GIT_ERROR_SSH = .git_error_t.GIT_ERROR_SSH, 295 GIT_ERROR_FILTER = .git_error_t.GIT_ERROR_FILTER, 296 GIT_ERROR_REVERT = .git_error_t.GIT_ERROR_REVERT, 297 GIT_ERROR_CALLBACK = .git_error_t.GIT_ERROR_CALLBACK, 298 GIT_ERROR_CHERRYPICK = .git_error_t.GIT_ERROR_CHERRYPICK, 299 GIT_ERROR_DESCRIBE = .git_error_t.GIT_ERROR_DESCRIBE, 300 GIT_ERROR_REBASE = .git_error_t.GIT_ERROR_REBASE, 301 GIT_ERROR_FILESYSTEM = .git_error_t.GIT_ERROR_FILESYSTEM, 302 GIT_ERROR_PATCH = .git_error_t.GIT_ERROR_PATCH, 303 GIT_ERROR_WORKTREE = .git_error_t.GIT_ERROR_WORKTREE, 304 GIT_ERROR_SHA1 = .git_error_t.GIT_ERROR_SHA1, 305 GIT_ERROR_HTTP = .git_error_t.GIT_ERROR_HTTP, 306 GIT_ERROR_INTERNAL = .git_error_t.GIT_ERROR_INTERNAL, 307 } 308 309 /** 310 * Return the last `git_error` object that was generated for the 311 * current thread. 312 * 313 * The default behaviour of this function is to return NULL if no previous error has occurred. 314 * However, libgit2's error strings are not cleared aggressively, so a prior 315 * (unrelated) error may be returned. This can be avoided by only calling 316 * this function if the prior call to a libgit2 API returned an error. 317 * 318 * Returns: A git_error object. 319 */ 320 //GIT_EXTERN 321 const (.git_error)* git_error_last(); 322 323 /** 324 * Clear the last library error that occurred for this thread. 325 */ 326 //GIT_EXTERN 327 void git_error_clear(); 328 329 /** 330 * Set the error message string for this thread. 331 * 332 * This function is public so that custom ODB backends and the like can 333 * relay an error message through libgit2. Most regular users of libgit2 334 * will never need to call this function -- actually, calling it in most 335 * circumstances (for example, calling from within a callback function) 336 * will just end up having the value overwritten by libgit2 internals. 337 * 338 * This error message is stored in thread-local storage and only applies 339 * to the particular thread that this libgit2 call is made from. 340 * 341 * Params: 342 * error_class = One of the `git_error_t` enum above describing the general subsystem that is responsible for the error. 343 * string_ = The formatted error message to keep 344 * 345 * Returns: 0 on success or -1 on failure 346 */ 347 //GIT_EXTERN 348 int git_error_set_str(int error_class, const (char)* string_); 349 350 /** 351 * Set the error message to a special value for memory allocation failure. 352 * 353 * The normal `git_error_set_str()` function attempts to `strdup()` the 354 * string that is passed in. This is not a good idea when the error in 355 * question is a memory allocation failure. That circumstance has a 356 * special setter function that sets the error string to a known and 357 * statically allocated internal value. 358 */ 359 //GIT_EXTERN 360 void git_error_set_oom(); 361 362 /** @} */