Blame include/git2/errors.h

Packit ae9e2a
/*
Packit ae9e2a
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit ae9e2a
 *
Packit ae9e2a
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit ae9e2a
 * a Linking Exception. For full terms see the included COPYING file.
Packit ae9e2a
 */
Packit ae9e2a
#ifndef INCLUDE_git_errors_h__
Packit ae9e2a
#define INCLUDE_git_errors_h__
Packit ae9e2a
Packit ae9e2a
#include "common.h"
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * @file git2/errors.h
Packit ae9e2a
 * @brief Git error handling routines and variables
Packit ae9e2a
 * @ingroup Git
Packit ae9e2a
 * @{
Packit ae9e2a
 */
Packit ae9e2a
GIT_BEGIN_DECL
Packit ae9e2a
Packit ae9e2a
/** Generic return codes */
Packit ae9e2a
typedef enum {
Packit ae9e2a
	GIT_OK         =  0,		/**< No error */
Packit ae9e2a
Packit ae9e2a
	GIT_ERROR      = -1,		/**< Generic error */
Packit ae9e2a
	GIT_ENOTFOUND  = -3,		/**< Requested object could not be found */
Packit ae9e2a
	GIT_EEXISTS    = -4,		/**< Object exists preventing operation */
Packit ae9e2a
	GIT_EAMBIGUOUS = -5,		/**< More than one object matches */
Packit ae9e2a
	GIT_EBUFS      = -6,		/**< Output buffer too short to hold data */
Packit ae9e2a
Packit ae9e2a
	/* GIT_EUSER is a special error that is never generated by libgit2
Packit ae9e2a
	 * code.  You can return it from a callback (e.g to stop an iteration)
Packit ae9e2a
	 * to know that it was generated by the callback and not by libgit2.
Packit ae9e2a
	 */
Packit ae9e2a
	GIT_EUSER      = -7,
Packit ae9e2a
Packit ae9e2a
	GIT_EBAREREPO       =  -8,	/**< Operation not allowed on bare repository */
Packit ae9e2a
	GIT_EUNBORNBRANCH   =  -9,	/**< HEAD refers to branch with no commits */
Packit ae9e2a
	GIT_EUNMERGED       = -10,	/**< Merge in progress prevented operation */
Packit ae9e2a
	GIT_ENONFASTFORWARD = -11,	/**< Reference was not fast-forwardable */
Packit ae9e2a
	GIT_EINVALIDSPEC    = -12,	/**< Name/ref spec was not in a valid format */
Packit ae9e2a
	GIT_ECONFLICT       = -13,	/**< Checkout conflicts prevented operation */
Packit ae9e2a
	GIT_ELOCKED         = -14,	/**< Lock file prevented operation */
Packit ae9e2a
	GIT_EMODIFIED       = -15,	/**< Reference value does not match expected */
Packit ae9e2a
	GIT_EAUTH           = -16,      /**< Authentication error */
Packit ae9e2a
	GIT_ECERTIFICATE    = -17,      /**< Server certificate is invalid */
Packit ae9e2a
	GIT_EAPPLIED        = -18,	/**< Patch/merge has already been applied */
Packit ae9e2a
	GIT_EPEEL           = -19,      /**< The requested peel operation is not possible */
Packit ae9e2a
	GIT_EEOF            = -20,      /**< Unexpected EOF */
Packit ae9e2a
	GIT_EINVALID        = -21,      /**< Invalid operation or input */
Packit ae9e2a
	GIT_EUNCOMMITTED    = -22,	/**< Uncommitted changes in index prevented operation */
Packit ae9e2a
	GIT_EDIRECTORY      = -23,      /**< The operation is not valid for a directory */
Packit ae9e2a
	GIT_EMERGECONFLICT  = -24,	/**< A merge conflict exists and cannot continue */
Packit ae9e2a
Packit ae9e2a
	GIT_PASSTHROUGH     = -30,	/**< Internal only */
Packit ae9e2a
	GIT_ITEROVER        = -31,	/**< Signals end of iteration with iterator */
Packit ae9e2a
	GIT_RETRY           = -32,	/**< Internal only */
Packit ae9e2a
	GIT_EMISMATCH       = -33,	/**< Hashsum mismatch in object */
Packit ae9e2a
} git_error_code;
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Structure to store extra details of the last error that occurred.
Packit ae9e2a
 *
Packit ae9e2a
 * This is kept on a per-thread basis if GIT_THREADS was defined when the
Packit ae9e2a
 * library was build, otherwise one is kept globally for the library
Packit ae9e2a
 */
Packit ae9e2a
typedef struct {
Packit ae9e2a
	char *message;
Packit ae9e2a
	int klass;
Packit ae9e2a
} git_error;
Packit ae9e2a
Packit ae9e2a
/** Error classes */
Packit ae9e2a
typedef enum {
Packit ae9e2a
	GITERR_NONE = 0,
Packit ae9e2a
	GITERR_NOMEMORY,
Packit ae9e2a
	GITERR_OS,
Packit ae9e2a
	GITERR_INVALID,
Packit ae9e2a
	GITERR_REFERENCE,
Packit ae9e2a
	GITERR_ZLIB,
Packit ae9e2a
	GITERR_REPOSITORY,
Packit ae9e2a
	GITERR_CONFIG,
Packit ae9e2a
	GITERR_REGEX,
Packit ae9e2a
	GITERR_ODB,
Packit ae9e2a
	GITERR_INDEX,
Packit ae9e2a
	GITERR_OBJECT,
Packit ae9e2a
	GITERR_NET,
Packit ae9e2a
	GITERR_TAG,
Packit ae9e2a
	GITERR_TREE,
Packit ae9e2a
	GITERR_INDEXER,
Packit ae9e2a
	GITERR_SSL,
Packit ae9e2a
	GITERR_SUBMODULE,
Packit ae9e2a
	GITERR_THREAD,
Packit ae9e2a
	GITERR_STASH,
Packit ae9e2a
	GITERR_CHECKOUT,
Packit ae9e2a
	GITERR_FETCHHEAD,
Packit ae9e2a
	GITERR_MERGE,
Packit ae9e2a
	GITERR_SSH,
Packit ae9e2a
	GITERR_FILTER,
Packit ae9e2a
	GITERR_REVERT,
Packit ae9e2a
	GITERR_CALLBACK,
Packit ae9e2a
	GITERR_CHERRYPICK,
Packit ae9e2a
	GITERR_DESCRIBE,
Packit ae9e2a
	GITERR_REBASE,
Packit ae9e2a
	GITERR_FILESYSTEM,
Packit ae9e2a
	GITERR_PATCH,
Packit ae9e2a
	GITERR_WORKTREE,
Packit ae9e2a
	GITERR_SHA1
Packit ae9e2a
} git_error_t;
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Return the last `git_error` object that was generated for the
Packit ae9e2a
 * current thread or NULL if no error has occurred.
Packit ae9e2a
 *
Packit ae9e2a
 * @return A git_error object.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(const git_error *) giterr_last(void);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Clear the last library error that occurred for this thread.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(void) giterr_clear(void);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Set the error message string for this thread.
Packit ae9e2a
 *
Packit ae9e2a
 * This function is public so that custom ODB backends and the like can
Packit ae9e2a
 * relay an error message through libgit2.  Most regular users of libgit2
Packit ae9e2a
 * will never need to call this function -- actually, calling it in most
Packit ae9e2a
 * circumstances (for example, calling from within a callback function)
Packit ae9e2a
 * will just end up having the value overwritten by libgit2 internals.
Packit ae9e2a
 *
Packit ae9e2a
 * This error message is stored in thread-local storage and only applies
Packit ae9e2a
 * to the particular thread that this libgit2 call is made from.
Packit ae9e2a
 *
Packit ae9e2a
 * @param error_class One of the `git_error_t` enum above describing the
Packit ae9e2a
 *                    general subsystem that is responsible for the error.
Packit ae9e2a
 * @param string The formatted error message to keep
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(void) giterr_set_str(int error_class, const char *string);
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Set the error message to a special value for memory allocation failure.
Packit ae9e2a
 *
Packit ae9e2a
 * The normal `giterr_set_str()` function attempts to `strdup()` the string
Packit ae9e2a
 * that is passed in.  This is not a good idea when the error in question
Packit ae9e2a
 * is a memory allocation failure.  That circumstance has a special setter
Packit ae9e2a
 * function that sets the error string to a known and statically allocated
Packit ae9e2a
 * internal value.
Packit ae9e2a
 */
Packit ae9e2a
GIT_EXTERN(void) giterr_set_oom(void);
Packit ae9e2a
Packit ae9e2a
/** @} */
Packit ae9e2a
GIT_END_DECL
Packit ae9e2a
#endif