]>
git.proxmox.com Git - libgit2.git/blob - src/errors.h
a2f60f752d820991b58cee7aca1f95149fcba11f
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.
8 #ifndef INCLUDE_errors_h__
9 #define INCLUDE_errors_h__
14 * Set the error message for this thread, formatting as needed.
16 void git_error_set(int error_class
, const char *fmt
, ...) GIT_FORMAT_PRINTF(2, 3);
17 void git_error_vset(int error_class
, const char *fmt
, va_list ap
);
20 * Set error message for user callback if needed.
22 * If the error code in non-zero and no error message is set, this
23 * sets a generic error message.
25 * @return This always returns the `error_code` parameter.
27 GIT_INLINE(int) git_error_set_after_callback_function(
28 int error_code
, const char *action
)
31 const git_error
*e
= git_error_last();
32 if (!e
|| !e
->message
)
33 git_error_set(e
? e
->klass
: GIT_ERROR_CALLBACK
,
34 "%s callback returned %d", action
, error_code
);
40 #define git_error_set_after_callback(code) \
41 git_error_set_after_callback_function((code), __FUNCTION__)
43 #define git_error_set_after_callback(code) \
44 git_error_set_after_callback_function((code), __func__)
48 * Gets the system error code for this thread.
50 int git_error_system_last(void);
53 * Sets the system error code for this thread.
55 void git_error_system_set(int code
);
58 * Structure to preserve libgit2 error state
67 * Capture current error state to restore later, returning error code.
68 * If `error_code` is zero, this does not clear the current error state.
69 * You must either restore this error state, or free it.
71 extern int git_error_state_capture(git_error_state
*state
, int error_code
);
74 * Restore error state to a previous value, returning saved error code.
76 extern int git_error_state_restore(git_error_state
*state
);
78 /** Free an error state. */
79 extern void git_error_state_free(git_error_state
*state
);