2 * errcode.h: internal interface for error reporting
4 * Copyright (C) 2009-2016 David Lutterkort
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Author: David Lutterkort <lutter@redhat.com>
27 /* Include augeas.h for the error codes */
31 * Error details in a separate struct that we can pass around
36 char *details; /* Human readable explanation */
37 const char *minor_details; /* Human readable version of MINOR */
38 /* A dummy info of last resort; this can be used in places where
39 * a struct info is needed but none available
42 /* Bit of a kludge to get at struct augeas, but since struct error
43 * is now available in a lot of places (through struct info), this
44 * gives a convenient way to get at the overall state
46 const struct augeas *aug;
47 /* A preallocated exception so that we can throw something, even
48 * under OOM conditions
53 void report_error(struct error *err, aug_errcode_t errcode,
54 const char *format, ...)
55 ATTRIBUTE_FORMAT(printf, 3, 4);
57 void bug_on(struct error *err, const char *srcfile, int srclineno,
58 const char *format, ...)
59 ATTRIBUTE_FORMAT(printf, 4, 5);
61 void reset_error(struct error *err);
63 #define HAS_ERR(obj) ((obj)->error->code != AUG_NOERROR)
65 #define ERR_BAIL(obj) if ((obj)->error->code != AUG_NOERROR) goto error;
67 #define ERR_RET(obj) if ((obj)->error->code != AUG_NOERROR) return;
69 #define ERR_NOMEM(cond, obj) \
71 report_error((obj)->error, AUG_ENOMEM, NULL); \
75 #define ERR_REPORT(obj, code, fmt ...) \
76 report_error((obj)->error, code, ## fmt)
78 #define ERR_THROW(cond, obj, code, fmt ...) \
81 report_error((obj)->error, code, ## fmt); \
86 #define ARG_CHECK(cond, obj, fmt ...) \
89 report_error((obj)->error, AUG_EBADARG, ## fmt); \
94 /* Assertions that use our error reporting infrastructure instead of
97 #define ensure(cond, obj) \
99 bug_on((obj)->error, __FILE__, __LINE__, NULL); \
102 #define ensure0(cond, obj) \
104 bug_on((obj)->error, __FILE__, __LINE__, NULL); \
108 #define BUG_ON(cond, obj, fmt ...) \
110 bug_on((obj)->error, __FILE__, __LINE__, ## fmt); \
119 * indent-tabs-mode: nil