|
Packit Service |
a2ae7a |
/*
|
|
Packit Service |
a2ae7a |
* errcode.h: internal interface for error reporting
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* Copyright (C) 2009-2016 David Lutterkort
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
a2ae7a |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
a2ae7a |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
a2ae7a |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
a2ae7a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2ae7a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
a2ae7a |
* Lesser General Public License for more details.
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
a2ae7a |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
a2ae7a |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
Packit Service |
a2ae7a |
*
|
|
Packit Service |
a2ae7a |
* Author: David Lutterkort <lutter@redhat.com>
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#ifndef ERRCODE_H_
|
|
Packit Service |
a2ae7a |
#define ERRCODE_H_
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "internal.h"
|
|
Packit Service |
a2ae7a |
/* Include augeas.h for the error codes */
|
|
Packit Service |
a2ae7a |
#include "augeas.h"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/*
|
|
Packit Service |
a2ae7a |
* Error details in a separate struct that we can pass around
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
struct error {
|
|
Packit Service |
a2ae7a |
aug_errcode_t code;
|
|
Packit Service |
a2ae7a |
int minor;
|
|
Packit Service |
a2ae7a |
char *details; /* Human readable explanation */
|
|
Packit Service |
a2ae7a |
const char *minor_details; /* Human readable version of MINOR */
|
|
Packit Service |
a2ae7a |
/* A dummy info of last resort; this can be used in places where
|
|
Packit Service |
a2ae7a |
* a struct info is needed but none available
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
struct info *info;
|
|
Packit Service |
a2ae7a |
/* Bit of a kludge to get at struct augeas, but since struct error
|
|
Packit Service |
a2ae7a |
* is now available in a lot of places (through struct info), this
|
|
Packit Service |
a2ae7a |
* gives a convenient way to get at the overall state
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
const struct augeas *aug;
|
|
Packit Service |
a2ae7a |
/* A preallocated exception so that we can throw something, even
|
|
Packit Service |
a2ae7a |
* under OOM conditions
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
struct value *exn;
|
|
Packit Service |
a2ae7a |
};
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
void report_error(struct error *err, aug_errcode_t errcode,
|
|
Packit Service |
a2ae7a |
const char *format, ...)
|
|
Packit Service |
a2ae7a |
ATTRIBUTE_FORMAT(printf, 3, 4);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
void bug_on(struct error *err, const char *srcfile, int srclineno,
|
|
Packit Service |
a2ae7a |
const char *format, ...)
|
|
Packit Service |
a2ae7a |
ATTRIBUTE_FORMAT(printf, 4, 5);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
void reset_error(struct error *err);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#define HAS_ERR(obj) ((obj)->error->code != AUG_NOERROR)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#define ERR_BAIL(obj) if ((obj)->error->code != AUG_NOERROR) goto error;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#define ERR_RET(obj) if ((obj)->error->code != AUG_NOERROR) return;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#define ERR_NOMEM(cond, obj) \
|
|
Packit Service |
a2ae7a |
if (cond) { \
|
|
Packit Service |
a2ae7a |
report_error((obj)->error, AUG_ENOMEM, NULL); \
|
|
Packit Service |
a2ae7a |
goto error; \
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#define ERR_REPORT(obj, code, fmt ...) \
|
|
Packit Service |
a2ae7a |
report_error((obj)->error, code, ## fmt)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#define ERR_THROW(cond, obj, code, fmt ...) \
|
|
Packit Service |
a2ae7a |
do { \
|
|
Packit Service |
a2ae7a |
if (cond) { \
|
|
Packit Service |
a2ae7a |
report_error((obj)->error, code, ## fmt); \
|
|
Packit Service |
a2ae7a |
goto error; \
|
|
Packit Service |
a2ae7a |
} \
|
|
Packit Service |
a2ae7a |
} while(0)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#define ARG_CHECK(cond, obj, fmt ...) \
|
|
Packit Service |
a2ae7a |
do { \
|
|
Packit Service |
a2ae7a |
if (cond) { \
|
|
Packit Service |
a2ae7a |
report_error((obj)->error, AUG_EBADARG, ## fmt); \
|
|
Packit Service |
a2ae7a |
goto error; \
|
|
Packit Service |
a2ae7a |
} \
|
|
Packit Service |
a2ae7a |
} while(0)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Assertions that use our error reporting infrastructure instead of
|
|
Packit Service |
a2ae7a |
* aborting
|
|
Packit Service |
a2ae7a |
*/
|
|
Packit Service |
a2ae7a |
#define ensure(cond, obj) \
|
|
Packit Service |
a2ae7a |
if (!(cond)) { \
|
|
Packit Service |
a2ae7a |
bug_on((obj)->error, __FILE__, __LINE__, NULL); \
|
|
Packit Service |
a2ae7a |
goto error; \
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
#define ensure0(cond, obj) \
|
|
Packit Service |
a2ae7a |
if (!(cond)) { \
|
|
Packit Service |
a2ae7a |
bug_on((obj)->error, __FILE__, __LINE__, NULL); \
|
|
Packit Service |
a2ae7a |
return NULL; \
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#define BUG_ON(cond, obj, fmt ...) \
|
|
Packit Service |
a2ae7a |
if (cond) { \
|
|
Packit Service |
a2ae7a |
bug_on((obj)->error, __FILE__, __LINE__, ## fmt); \
|
|
Packit Service |
a2ae7a |
goto error; \
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#endif
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/*
|
|
Packit Service |
a2ae7a |
* Local variables:
|
|
Packit Service |
a2ae7a |
* indent-tabs-mode: nil
|
|
Packit Service |
a2ae7a |
* c-indent-level: 4
|
|
Packit Service |
a2ae7a |
* c-basic-offset: 4
|
|
Packit Service |
a2ae7a |
* tab-width: 4
|
|
Packit Service |
a2ae7a |
* End:
|
|
Packit Service |
a2ae7a |
*/
|