]>
git.proxmox.com Git - libgit2.git/blob - include/git2/errors.h
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_git_errors_h__
8 #define INCLUDE_git_errors_h__
14 * @brief Git error handling routines and variables
20 /** Generic return codes */
22 GIT_OK
= 0, /*< No error */
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 */
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.
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_EMERGECONFLICT
= -13, /*< Merge conflicts prevented operation */
42 GIT_ELOCKED
= -14, /*< Lock file prevented operation */
43 GIT_EMODIFIED
= -15, /*< Reference value does not match expected */
44 GIT_ENOACCESS
= -16, /*< Access denied attempting operation */
46 GIT_PASSTHROUGH
= -30, /*< Internal only */
47 GIT_ITEROVER
= -31, /*< Signals end of iteration with iterator */
51 * Structure to store extra details of the last error that occurred.
53 * This is kept on a per-thread basis if GIT_THREADS was defined when the
54 * library was build, otherwise one is kept globally for the library
94 * Return the last `git_error` object that was generated for the
95 * current thread or NULL if no error has occurred.
97 * @return A git_error object.
99 GIT_EXTERN(const git_error
*) giterr_last(void);
102 * Clear the last library error that occurred for this thread.
104 GIT_EXTERN(void) giterr_clear(void);
107 * Get the last error data and clear it.
109 * This copies the last error into the given `git_error` struct
110 * and returns 0 if the copy was successful, leaving the error
111 * cleared as if `giterr_clear` had been called.
113 * If there was no existing error in the library, -1 will be returned
114 * and the contents of `cpy` will be left unmodified.
116 GIT_EXTERN(int) giterr_detach(git_error
*cpy
);
119 * Set the error message string for this thread.
121 * This function is public so that custom ODB backends and the like can
122 * relay an error message through libgit2. Most regular users of libgit2
123 * will never need to call this function -- actually, calling it in most
124 * circumstances (for example, calling from within a callback function)
125 * will just end up having the value overwritten by libgit2 internals.
127 * This error message is stored in thread-local storage and only applies
128 * to the particular thread that this libgit2 call is made from.
130 * NOTE: Passing the `error_class` as GITERR_OS has a special behavior: we
131 * attempt to append the system default error message for the last OS error
132 * that occurred and then clear the last error. The specific implementation
133 * of looking up and clearing this last OS error will vary by platform.
135 * @param error_class One of the `git_error_t` enum above describing the
136 * general subsystem that is responsible for the error.
137 * @param string The formatted error message to keep
139 GIT_EXTERN(void) giterr_set_str(int error_class
, const char *string
);
142 * Set the error message to a special value for memory allocation failure.
144 * The normal `giterr_set_str()` function attempts to `strdup()` the string
145 * that is passed in. This is not a good idea when the error in question
146 * is a memory allocation failure. That circumstance has a special setter
147 * function that sets the error string to a known and statically allocated
150 GIT_EXTERN(void) giterr_set_oom(void);