]> git.proxmox.com Git - libgit2.git/blob - include/git2/errors.h
6f5580253b044959984f9905132840c35832528e
[libgit2.git] / include / git2 / errors.h
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 #ifndef INCLUDE_git_errors_h__
8 #define INCLUDE_git_errors_h__
9
10 #include "common.h"
11
12 /**
13 * @file git2/errors.h
14 * @brief Git error handling routines and variables
15 * @ingroup Git
16 * @{
17 */
18 GIT_BEGIN_DECL
19
20 /** Generic return codes */
21 typedef enum {
22 GIT_OK = 0, /**< No error */
23
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 */
29
30 /* GIT_EUSER is a special error that is never generated by libgit2
31 * code. You can return it from a callback (e.g to stop an iteration)
32 * to know that it was generated by the callback and not by libgit2.
33 */
34 GIT_EUSER = -7,
35
36 GIT_EBAREREPO = -8, /**< Operation not allowed on bare repository */
37 GIT_EUNBORNBRANCH = -9, /**< HEAD refers to branch with no commits */
38 GIT_EUNMERGED = -10, /**< Merge in progress prevented operation */
39 GIT_ENONFASTFORWARD = -11, /**< Reference was not fast-forwardable */
40 GIT_EINVALIDSPEC = -12, /**< Name/ref spec was not in a valid format */
41 GIT_ECONFLICT = -13, /**< Checkout conflicts prevented operation */
42 GIT_ELOCKED = -14, /**< Lock file prevented operation */
43 GIT_EMODIFIED = -15, /**< Reference value does not match expected */
44 GIT_EAUTH = -16, /**< Authentication error */
45 GIT_ECERTIFICATE = -17, /**< Server certificate is invalid */
46 GIT_EAPPLIED = -18, /**< Patch/merge has already been applied */
47 GIT_EPEEL = -19, /**< The requested peel operation is not possible */
48 GIT_EEOF = -20, /**< Unexpected EOF */
49 GIT_EINVALID = -21, /**< Invalid operation or input */
50 GIT_EUNCOMMITTED = -22, /**< Uncommitted changes in index prevented operation */
51 GIT_EDIRECTORY = -23, /**< The operation is not valid for a directory */
52 GIT_EMERGECONFLICT = -24, /**< A merge conflict exists and cannot continue */
53
54 GIT_PASSTHROUGH = -30, /**< Internal only */
55 GIT_ITEROVER = -31, /**< Signals end of iteration with iterator */
56 GIT_RETRY = -32, /**< Internal only */
57 GIT_EMISMATCH = -33, /**< Hashsum mismatch in object */
58 } git_error_code;
59
60 /**
61 * Structure to store extra details of the last error that occurred.
62 *
63 * This is kept on a per-thread basis if GIT_THREADS was defined when the
64 * library was build, otherwise one is kept globally for the library
65 */
66 typedef struct {
67 char *message;
68 int klass;
69 } git_error;
70
71 /** Error classes */
72 typedef enum {
73 GITERR_NONE = 0,
74 GITERR_NOMEMORY,
75 GITERR_OS,
76 GITERR_INVALID,
77 GITERR_REFERENCE,
78 GITERR_ZLIB,
79 GITERR_REPOSITORY,
80 GITERR_CONFIG,
81 GITERR_REGEX,
82 GITERR_ODB,
83 GITERR_INDEX,
84 GITERR_OBJECT,
85 GITERR_NET,
86 GITERR_TAG,
87 GITERR_TREE,
88 GITERR_INDEXER,
89 GITERR_SSL,
90 GITERR_SUBMODULE,
91 GITERR_THREAD,
92 GITERR_STASH,
93 GITERR_CHECKOUT,
94 GITERR_FETCHHEAD,
95 GITERR_MERGE,
96 GITERR_SSH,
97 GITERR_FILTER,
98 GITERR_REVERT,
99 GITERR_CALLBACK,
100 GITERR_CHERRYPICK,
101 GITERR_DESCRIBE,
102 GITERR_REBASE,
103 GITERR_FILESYSTEM,
104 GITERR_PATCH,
105 GITERR_WORKTREE,
106 GITERR_SHA1
107 } git_error_t;
108
109 /**
110 * Return the last `git_error` object that was generated for the
111 * current thread or NULL if no error has occurred.
112 *
113 * @return A git_error object.
114 */
115 GIT_EXTERN(const git_error *) giterr_last(void);
116
117 /**
118 * Clear the last library error that occurred for this thread.
119 */
120 GIT_EXTERN(void) giterr_clear(void);
121
122 /**
123 * Set the error message string for this thread.
124 *
125 * This function is public so that custom ODB backends and the like can
126 * relay an error message through libgit2. Most regular users of libgit2
127 * will never need to call this function -- actually, calling it in most
128 * circumstances (for example, calling from within a callback function)
129 * will just end up having the value overwritten by libgit2 internals.
130 *
131 * This error message is stored in thread-local storage and only applies
132 * to the particular thread that this libgit2 call is made from.
133 *
134 * @param error_class One of the `git_error_t` enum above describing the
135 * general subsystem that is responsible for the error.
136 * @param string The formatted error message to keep
137 */
138 GIT_EXTERN(void) giterr_set_str(int error_class, const char *string);
139
140 /**
141 * Set the error message to a special value for memory allocation failure.
142 *
143 * The normal `giterr_set_str()` function attempts to `strdup()` the string
144 * that is passed in. This is not a good idea when the error in question
145 * is a memory allocation failure. That circumstance has a special setter
146 * function that sets the error string to a known and statically allocated
147 * internal value.
148 */
149 GIT_EXTERN(void) giterr_set_oom(void);
150
151 /** @} */
152 GIT_END_DECL
153 #endif