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