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 /** 179 * Structure to store extra details of the last error that occurred. 180 * 181 * This is kept on a per-thread basis if GIT_THREADS was defined when the 182 * library was build, otherwise one is kept globally for the library 183 */ 184 struct git_error 185 { 186 char* message; 187 int klass; 188 } 189 190 /** 191 * Error classes 192 */ 193 enum git_error_t 194 { 195 GIT_ERROR_NONE = 0, 196 GIT_ERROR_NOMEMORY, 197 GIT_ERROR_OS, 198 GIT_ERROR_INVALID, 199 GIT_ERROR_REFERENCE, 200 GIT_ERROR_ZLIB, 201 GIT_ERROR_REPOSITORY, 202 GIT_ERROR_CONFIG, 203 GIT_ERROR_REGEX, 204 GIT_ERROR_ODB, 205 GIT_ERROR_INDEX, 206 GIT_ERROR_OBJECT, 207 GIT_ERROR_NET, 208 GIT_ERROR_TAG, 209 GIT_ERROR_TREE, 210 GIT_ERROR_INDEXER, 211 GIT_ERROR_SSL, 212 GIT_ERROR_SUBMODULE, 213 GIT_ERROR_THREAD, 214 GIT_ERROR_STASH, 215 GIT_ERROR_CHECKOUT, 216 GIT_ERROR_FETCHHEAD, 217 GIT_ERROR_MERGE, 218 GIT_ERROR_SSH, 219 GIT_ERROR_FILTER, 220 GIT_ERROR_REVERT, 221 GIT_ERROR_CALLBACK, 222 GIT_ERROR_CHERRYPICK, 223 GIT_ERROR_DESCRIBE, 224 GIT_ERROR_REBASE, 225 GIT_ERROR_FILESYSTEM, 226 GIT_ERROR_PATCH, 227 GIT_ERROR_WORKTREE, 228 GIT_ERROR_SHA1, 229 GIT_ERROR_HTTP, 230 } 231 232 /** 233 * Return the last `git_error` object that was generated for the 234 * current thread. 235 * 236 * The default behaviour of this function is to return NULL if no previous error has occurred. 237 * However, libgit2's error strings are not cleared aggressively, so a prior 238 * (unrelated) error may be returned. This can be avoided by only calling 239 * this function if the prior call to a libgit2 API returned an error. 240 * 241 * @return A git_error object. 242 */ 243 //GIT_EXTERN 244 const (.git_error)* git_error_last(); 245 246 /** 247 * Clear the last library error that occurred for this thread. 248 */ 249 //GIT_EXTERN 250 void git_error_clear(); 251 252 /** 253 * Set the error message string for this thread. 254 * 255 * This function is public so that custom ODB backends and the like can 256 * relay an error message through libgit2. Most regular users of libgit2 257 * will never need to call this function -- actually, calling it in most 258 * circumstances (for example, calling from within a callback function) 259 * will just end up having the value overwritten by libgit2 internals. 260 * 261 * This error message is stored in thread-local storage and only applies 262 * to the particular thread that this libgit2 call is made from. 263 * 264 * @param error_class One of the `git_error_t` enum above describing the 265 * general subsystem that is responsible for the error. 266 * @param string_ The formatted error message to keep 267 * @return 0 on success or -1 on failure 268 */ 269 //GIT_EXTERN 270 int git_error_set_str(int error_class, const (char)* string_); 271 272 /** 273 * Set the error message to a special value for memory allocation failure. 274 * 275 * The normal `git_error_set_str()` function attempts to `strdup()` the 276 * string that is passed in. This is not a good idea when the error in 277 * question is a memory allocation failure. That circumstance has a 278 * special setter function that sets the error string to a known and 279 * statically allocated internal value. 280 */ 281 //GIT_EXTERN 282 void git_error_set_oom(); 283 284 /** @} */