summaryrefslogtreecommitdiff
path: root/src/errors.h
blob: 525cb0f09b87109a6e27a3047294a0e86aa2d71d (plain)
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
#ifndef INCLUDE_errors_h__
#define INCLUDE_errors_h__

#include "git2/common.h"

/* Deprecated - please use the more advanced functions below. */
#define git__throw(error, ...) \
	(git_error_createf(__FILE__, __LINE__, error, __VA_ARGS__), error)

#define git__rethrow(error, ...) \
	(git_error_createf(__FILE__, __LINE__, error, __VA_ARGS__), error)

/*
 * This implementation is loosely based on subversion's error
 * handling.
 */

git_error * git_error_createf(const char *file, unsigned int line, int code,
			      const char *msg, ...) GIT_FORMAT_PRINTF(4, 5);

git_error * git_error__quick_wrap(const char *file, int line,
				 git_error_code error, const char *msg);

/*
 * Wrap an error with a message. All git_error values are assigned with
 * child's fields.
 */
#define git_error_quick_wrap(error, message)				\
	git_error__quick_wrap(__FILE__, __LINE__, error, message)

/*
 * Use this function to wrap functions like
 *
 *	git_error * foo(void)
 *	{
 *		return git_error_trace(bar());
 *	}
 *
 * Otherwise the call of foo() wouldn't be visible in the trace.
 *
 */
#define git_error_trace(error) \
	git_error_quick_wrap(error, "traced error");

/* Throw an out-of-memory error */
extern git_error * git_error_oom(void);

#endif /* INCLUDE_errors_h__ */