Hash :
300d192f
Author :
Date :
2013-12-02T11:15:27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_errors_h__
#define INCLUDE_git_errors_h__
#include "common.h"
#include "buffer.h"
/**
* @file git2/errors.h
* @brief Git error handling routines and variables
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/** Generic return codes */
typedef enum {
GIT_OK = 0,
GIT_ERROR = -1,
GIT_ENOTFOUND = -3,
GIT_EEXISTS = -4,
GIT_EAMBIGUOUS = -5,
GIT_EBUFS = -6,
GIT_EUSER = -7,
GIT_EBAREREPO = -8,
GIT_EUNBORNBRANCH = -9,
GIT_EUNMERGED = -10,
GIT_ENONFASTFORWARD = -11,
GIT_EINVALIDSPEC = -12,
GIT_EMERGECONFLICT = -13,
GIT_ELOCKED = -14,
GIT_PASSTHROUGH = -30,
GIT_ITEROVER = -31,
} git_error_code;
typedef struct {
char *message;
int klass;
} git_error;
/** Error classes */
typedef enum {
GITERR_NONE = 0,
GITERR_NOMEMORY,
GITERR_OS,
GITERR_INVALID,
GITERR_REFERENCE,
GITERR_ZLIB,
GITERR_REPOSITORY,
GITERR_CONFIG,
GITERR_REGEX,
GITERR_ODB,
GITERR_INDEX,
GITERR_OBJECT,
GITERR_NET,
GITERR_TAG,
GITERR_TREE,
GITERR_INDEXER,
GITERR_SSL,
GITERR_SUBMODULE,
GITERR_THREAD,
GITERR_STASH,
GITERR_CHECKOUT,
GITERR_FETCHHEAD,
GITERR_MERGE,
GITERR_SSH,
GITERR_FILTER,
GITERR_REVERT,
} git_error_t;
/**
* Return the last `git_error` object that was generated for the
* current thread or NULL if no error has occurred.
*
* @return A git_error object.
*/
GIT_EXTERN(const git_error *) giterr_last(void);
/**
* Clear the last library error that occurred for this thread.
*/
GIT_EXTERN(void) giterr_clear(void);
/**
* Get the last error data and clear it.
*
* This copies the last error into the given `git_error` struct
* and returns 0 if the copy was successful, leaving the error
* cleared as if `giterr_clear` had been called.
*
* If there was no existing error in the library, -1 will be returned
* and the contents of `cpy` will be left unmodified.
*/
GIT_EXTERN(int) giterr_detach(git_error *cpy);
/**
* Set the error message string for this thread.
*
* This function is public so that custom ODB backends and the like can
* relay an error message through libgit2. Most regular users of libgit2
* will never need to call this function -- actually, calling it in most
* circumstances (for example, calling from within a callback function)
* will just end up having the value overwritten by libgit2 internals.
*
* This error message is stored in thread-local storage and only applies
* to the particular thread that this libgit2 call is made from.
*
* NOTE: Passing the `error_class` as GITERR_OS has a special behavior: we
* attempt to append the system default error message for the last OS error
* that occurred and then clear the last error. The specific implementation
* of looking up and clearing this last OS error will vary by platform.
*
* @param error_class One of the `git_error_t` enum above describing the
* general subsystem that is responsible for the error.
* @param string The formatted error message to keep
*/
GIT_EXTERN(void) giterr_set_str(int error_class, const char *string);
/**
* Set the error message to a special value for memory allocation failure.
*
* The normal `giterr_set_str()` function attempts to `strdup()` the string
* that is passed in. This is not a good idea when the error in question
* is a memory allocation failure. That circumstance has a special setter
* function that sets the error string to a known and statically allocated
* internal value.
*/
GIT_EXTERN(void) giterr_set_oom(void);
/** @} */
GIT_END_DECL
#endif