]>
Commit | Line | Data |
---|---|---|
f5918330 | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
f5918330 | 3 | * |
bb742ede VM |
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. | |
f5918330 | 6 | */ |
ae234862 AE |
7 | #ifndef INCLUDE_git_errors_h__ |
8 | #define INCLUDE_git_errors_h__ | |
b3039bee | 9 | |
f31bd03f VM |
10 | #include "common.h" |
11 | ||
ae234862 | 12 | /** |
f5918330 | 13 | * @file git2/errors.h |
ae234862 AE |
14 | * @brief Git error handling routines and variables |
15 | * @ingroup Git | |
16 | * @{ | |
17 | */ | |
ae234862 AE |
18 | GIT_BEGIN_DECL |
19 | ||
e172cf08 | 20 | /** Generic return codes */ |
0f1f9833 | 21 | typedef enum { |
31b0cb51 | 22 | GIT_OK = 0, /**< No error */ |
904b67e6 | 23 | |
31b0cb51 MA |
24 | GIT_ERROR = -1, /**< Generic error */ |
25 | GIT_ENOTFOUND = -3, /**< Requested object could not be found */ | |
26 | GIT_EEXISTS = -4, /**< Object exists preventing operation */ | |
27 | GIT_EAMBIGUOUS = -5, /**< More than one object matches */ | |
28 | GIT_EBUFS = -6, /**< Output buffer too short to hold data */ | |
373cf6a9 | 29 | |
ac3d33df JK |
30 | /** |
31 | * GIT_EUSER is a special error that is never generated by libgit2 | |
373cf6a9 RB |
32 | * code. You can return it from a callback (e.g to stop an iteration) |
33 | * to know that it was generated by the callback and not by libgit2. | |
34 | */ | |
35 | GIT_EUSER = -7, | |
36 | ||
31b0cb51 MA |
37 | GIT_EBAREREPO = -8, /**< Operation not allowed on bare repository */ |
38 | GIT_EUNBORNBRANCH = -9, /**< HEAD refers to branch with no commits */ | |
39 | GIT_EUNMERGED = -10, /**< Merge in progress prevented operation */ | |
40 | GIT_ENONFASTFORWARD = -11, /**< Reference was not fast-forwardable */ | |
41 | GIT_EINVALIDSPEC = -12, /**< Name/ref spec was not in a valid format */ | |
885b94aa | 42 | GIT_ECONFLICT = -13, /**< Checkout conflicts prevented operation */ |
31b0cb51 MA |
43 | GIT_ELOCKED = -14, /**< Lock file prevented operation */ |
44 | GIT_EMODIFIED = -15, /**< Reference value does not match expected */ | |
c25aa7cd PP |
45 | GIT_EAUTH = -16, /**< Authentication error */ |
46 | GIT_ECERTIFICATE = -17, /**< Server certificate is invalid */ | |
93a7004c | 47 | GIT_EAPPLIED = -18, /**< Patch/merge has already been applied */ |
c25aa7cd PP |
48 | GIT_EPEEL = -19, /**< The requested peel operation is not possible */ |
49 | GIT_EEOF = -20, /**< Unexpected EOF */ | |
50 | GIT_EINVALID = -21, /**< Invalid operation or input */ | |
82b1c93d | 51 | GIT_EUNCOMMITTED = -22, /**< Uncommitted changes in index prevented operation */ |
c25aa7cd | 52 | GIT_EDIRECTORY = -23, /**< The operation is not valid for a directory */ |
8683d31f | 53 | GIT_EMERGECONFLICT = -24, /**< A merge conflict exists and cannot continue */ |
31b0cb51 | 54 | |
ac3d33df | 55 | GIT_PASSTHROUGH = -30, /**< A user-configured callback refused to act */ |
31b0cb51 | 56 | GIT_ITEROVER = -31, /**< Signals end of iteration with iterator */ |
cc8d9a29 | 57 | GIT_RETRY = -32, /**< Internal only */ |
28a0741f | 58 | GIT_EMISMATCH = -33, /**< Hashsum mismatch in object */ |
ac3d33df JK |
59 | GIT_EINDEXDIRTY = -34, /**< Unsaved changes in the index would be overwritten */ |
60 | GIT_EAPPLYFAIL = -35, /**< Patch application failed */ | |
e579e0f7 | 61 | GIT_EOWNER = -36 /**< The object is not owned by the current user */ |
0f1f9833 | 62 | } git_error_code; |
60bc2d20 | 63 | |
373cf6a9 RB |
64 | /** |
65 | * Structure to store extra details of the last error that occurred. | |
66 | * | |
67 | * This is kept on a per-thread basis if GIT_THREADS was defined when the | |
68 | * library was build, otherwise one is kept globally for the library | |
69 | */ | |
60bc2d20 VM |
70 | typedef struct { |
71 | char *message; | |
72 | int klass; | |
f87d9beb | 73 | } git_error; |
6810bf28 | 74 | |
798e4d53 | 75 | /** Error classes */ |
60bc2d20 | 76 | typedef enum { |
ac3d33df JK |
77 | GIT_ERROR_NONE = 0, |
78 | GIT_ERROR_NOMEMORY, | |
79 | GIT_ERROR_OS, | |
80 | GIT_ERROR_INVALID, | |
81 | GIT_ERROR_REFERENCE, | |
82 | GIT_ERROR_ZLIB, | |
83 | GIT_ERROR_REPOSITORY, | |
84 | GIT_ERROR_CONFIG, | |
85 | GIT_ERROR_REGEX, | |
86 | GIT_ERROR_ODB, | |
87 | GIT_ERROR_INDEX, | |
88 | GIT_ERROR_OBJECT, | |
89 | GIT_ERROR_NET, | |
90 | GIT_ERROR_TAG, | |
91 | GIT_ERROR_TREE, | |
92 | GIT_ERROR_INDEXER, | |
93 | GIT_ERROR_SSL, | |
94 | GIT_ERROR_SUBMODULE, | |
95 | GIT_ERROR_THREAD, | |
96 | GIT_ERROR_STASH, | |
97 | GIT_ERROR_CHECKOUT, | |
98 | GIT_ERROR_FETCHHEAD, | |
99 | GIT_ERROR_MERGE, | |
100 | GIT_ERROR_SSH, | |
101 | GIT_ERROR_FILTER, | |
102 | GIT_ERROR_REVERT, | |
103 | GIT_ERROR_CALLBACK, | |
104 | GIT_ERROR_CHERRYPICK, | |
105 | GIT_ERROR_DESCRIBE, | |
106 | GIT_ERROR_REBASE, | |
107 | GIT_ERROR_FILESYSTEM, | |
108 | GIT_ERROR_PATCH, | |
109 | GIT_ERROR_WORKTREE, | |
22a2d3d5 UG |
110 | GIT_ERROR_SHA1, |
111 | GIT_ERROR_HTTP, | |
112 | GIT_ERROR_INTERNAL | |
e172cf08 | 113 | } git_error_t; |
60bc2d20 | 114 | |
e3c47510 RB |
115 | /** |
116 | * Return the last `git_error` object that was generated for the | |
ac3d33df JK |
117 | * current thread. |
118 | * | |
119 | * The default behaviour of this function is to return NULL if no previous error has occurred. | |
120 | * However, libgit2's error strings are not cleared aggressively, so a prior | |
121 | * (unrelated) error may be returned. This can be avoided by only calling | |
122 | * this function if the prior call to a libgit2 API returned an error. | |
e3c47510 RB |
123 | * |
124 | * @return A git_error object. | |
125 | */ | |
ac3d33df | 126 | GIT_EXTERN(const git_error *) git_error_last(void); |
e3c47510 RB |
127 | |
128 | /** | |
129 | * Clear the last library error that occurred for this thread. | |
130 | */ | |
ac3d33df | 131 | GIT_EXTERN(void) git_error_clear(void); |
e3c47510 | 132 | |
1a628100 RB |
133 | /** |
134 | * Set the error message string for this thread. | |
135 | * | |
136 | * This function is public so that custom ODB backends and the like can | |
137 | * relay an error message through libgit2. Most regular users of libgit2 | |
138 | * will never need to call this function -- actually, calling it in most | |
139 | * circumstances (for example, calling from within a callback function) | |
140 | * will just end up having the value overwritten by libgit2 internals. | |
141 | * | |
142 | * This error message is stored in thread-local storage and only applies | |
143 | * to the particular thread that this libgit2 call is made from. | |
144 | * | |
1a628100 RB |
145 | * @param error_class One of the `git_error_t` enum above describing the |
146 | * general subsystem that is responsible for the error. | |
e1967164 | 147 | * @param string The formatted error message to keep |
22a2d3d5 | 148 | * @return 0 on success or -1 on failure |
1a628100 | 149 | */ |
22a2d3d5 | 150 | GIT_EXTERN(int) git_error_set_str(int error_class, const char *string); |
1a628100 RB |
151 | |
152 | /** | |
153 | * Set the error message to a special value for memory allocation failure. | |
154 | * | |
ac3d33df JK |
155 | * The normal `git_error_set_str()` function attempts to `strdup()` the |
156 | * string that is passed in. This is not a good idea when the error in | |
157 | * question is a memory allocation failure. That circumstance has a | |
158 | * special setter function that sets the error string to a known and | |
159 | * statically allocated internal value. | |
1a628100 | 160 | */ |
ac3d33df | 161 | GIT_EXTERN(void) git_error_set_oom(void); |
1a628100 | 162 | |
ae234862 AE |
163 | /** @} */ |
164 | GIT_END_DECL | |
165 | #endif |