Libical API Documentation 4.0
Loading...
Searching...
No Matches
icalerror.h
Go to the documentation of this file.
1/*======================================================================
2 FILE: icalerror.h
3 CREATOR: eric 09 May 1999
4
5 SPDX-FileCopyrightText: 2000, Eric Busboom <eric@civicknowledge.com>
6
7 SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
8
9 The original code is icalerror.h
10======================================================================*/
11
12#ifndef ICALERROR_H
13#define ICALERROR_H
14
15#include "libical_ical_export.h"
16#include <assert.h>
17#include <stdio.h>
18
30
31#define ICAL_SETERROR_ISFUNC
32
43LIBICAL_ICAL_EXPORT void icalerror_stop_here(void);
44
51LIBICAL_ICAL_EXPORT void icalerror_crash_here(void);
52
53#ifndef _MSC_VER
54#pragma GCC visibility push(default)
55#endif
66typedef enum icalerrorenum
67{
70
73
76
79
82
85
87 ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */
88
91
94
97
99 ICAL_UNKNOWN_ERROR /* Used for problems in input to icalerror_strerror() */
101#ifndef _MSC_VER
102#pragma GCC visibility pop
103#endif
104
117LIBICAL_ICAL_EXPORT icalerrorenum *icalerrno_return(void);
118
135#define icalerrno (*(icalerrno_return()))
136
149LIBICAL_ICAL_EXPORT void icalerror_set_errors_are_fatal(int fatal);
150
164LIBICAL_ICAL_EXPORT int icalerror_get_errors_are_fatal(void);
165
166/* Warning messages */
167
178
179#ifdef __GNUC__ca
180#define icalerror_warn(message) \
181 { \
182 icalerrprintf("%s(), %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, message); \
183 }
184#else /* __GNU_C__ */
185#define icalerror_warn(message) \
186 { \
187 icalerrprintf("%s:%d: %s\n", __FILE__, __LINE__, message); \
188 }
189#endif /* __GNU_C__ */
190
202LIBICAL_ICAL_EXPORT void icalerror_clear_errno(void);
203
223
244LIBICAL_ICAL_EXPORT const char *icalerror_strerror(icalerrorenum e);
245
264LIBICAL_ICAL_EXPORT const char *icalerror_perror(void);
265
277LIBICAL_ICAL_EXPORT void ical_bt(void);
278
292LIBICAL_ICAL_EXPORT void icalerror_set_error_state(icalerrorenum error, icalerrorstate state);
293
300
316LIBICAL_ICAL_EXPORT icalerrorenum icalerror_error_from_string(const char *str);
317
333#if !defined(ICAL_SETERROR_ISFUNC)
334#define icalerror_set_errno(x) \
335 icalerrno = x; \
336 if (icalerror_get_error_state(x) == ICAL_ERROR_FATAL || \
337 (icalerror_get_error_state(x) == ICAL_ERROR_DEFAULT && \
338 icalerror_get_errors_are_fatal() == 1)) { \
339 icalerror_warn(icalerror_strerror(x)); \
340 ical_bt(); \
341 icalassert(0); \
342 } \
343 }
344#else
359LIBICAL_ICAL_EXPORT void icalerror_set_errno(icalerrorenum x);
360#endif
361
373
374#if !defined(ICAL_ERRORS_ARE_FATAL)
375#define ICAL_ERRORS_ARE_FATAL 0
376#endif
377
378#if ICAL_ERRORS_ARE_FATAL == 1
379#undef NDEBUG
380#endif
381
382#define icalerror_check_value_type(value, type) ;
383#define icalerror_check_property_type(value, type) ;
384#define icalerror_check_parameter_type(value, type) ;
385#define icalerror_check_component_type(value, type) ;
386
387/* Assert with a message */
399#if ICAL_ERRORS_ARE_FATAL == 1
400
401#ifdef __GNUC__
402#define icalerror_assert(test, message) \
403 if (!(test)) { \
404 icalerrprintf("%s(), %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, message); \
405 icalerror_stop_here(); \
406 abort(); \
407 }
408#else /*__GNUC__*/
409#define icalerror_assert(test, message) \
410 if (!(test)) { \
411 icalerrprintf("%s:%d: %s\n", __FILE__, __LINE__, message); \
412 icalerror_stop_here(); \
413 abort(); \
414 }
415#endif /*__GNUC__*/
416
417#else /* ICAL_ERRORS_ARE_FATAL */
418#define icalerror_assert(test, message)
419#endif /* ICAL_ERRORS_ARE_FATAL */
420
439#define icalerror_check_arg(test, arg) \
440 if (!(test)) { \
441 icalerror_set_errno(ICAL_BADARG_ERROR); \
442 }
443
463#define icalerror_check_arg_rv(test, arg) \
464 if (!(test)) { \
465 icalerror_set_errno(ICAL_BADARG_ERROR); \
466 return; \
467 }
468
489#define icalerror_check_arg_rz(test, arg) \
490 if (!(test)) { \
491 icalerror_set_errno(ICAL_BADARG_ERROR); \
492 return 0; \
493 }
494
516#define icalerror_check_arg_re(test, arg, error) \
517 if (!(test)) { \
518 icalerror_stop_here(); \
519 icalassert(0); \
520 return error; \
521 }
522
544#define icalerror_check_arg_rx(test, arg, x) \
545 if (!(test)) { \
546 icalerror_set_errno(ICAL_BADARG_ERROR); \
547 return x; \
548 }
549
550/* String interfaces to set an error to NONFATAL and restore it to its original value */
551
567LIBICAL_ICAL_EXPORT icalerrorstate icalerror_supress(const char *error);
568
587LIBICAL_ICAL_EXPORT void icalerror_restore(const char *error, icalerrorstate es);
588
589#endif /* !ICALERROR_H */
icalerrorenum * icalerrno_return(void)
Returns the current icalerrno value.
Definition icalerror.c:42
void icalerror_set_errors_are_fatal(int fatal)
Change if errors are fatal.
Definition icalerror.c:107
void icalerror_crash_here(void)
Triggered to abort the process.
Definition icalerror.c:76
void ical_bt(void)
Prints backtrace.
Definition icalerror.c:258
icalerrorstate
Determine if an error is fatal or non-fatal.
Definition icalerror.h:210
@ ICAL_ERROR_UNKNOWN
Definition icalerror.h:221
@ ICAL_ERROR_FATAL
Definition icalerror.h:212
@ ICAL_ERROR_DEFAULT
Definition icalerror.h:218
@ ICAL_ERROR_NONFATAL
Definition icalerror.h:215
int icalerror_get_errors_are_fatal(void)
Determine if errors are fatal.
Definition icalerror.c:112
const char * icalerror_perror(void)
Returns the description string for the current error in icalerrno.
Definition icalerror.c:207
icalerrorstate icalerror_get_error_state(icalerrorenum error)
Gets the error state (severity) for a given error.
Definition icalerror.c:232
icalerrorenum
Represents the different types of errors that can be triggered in libical.
Definition icalerror.h:67
@ ICAL_NEWFAILED_ERROR
Definition icalerror.h:75
@ ICAL_BADARG_ERROR
Definition icalerror.h:72
@ ICAL_FILE_ERROR
Definition icalerror.h:90
@ ICAL_ALLOCATION_ERROR
Definition icalerror.h:78
@ ICAL_INTERNAL_ERROR
Definition icalerror.h:87
@ ICAL_NO_ERROR
Definition icalerror.h:69
@ ICAL_MALFORMEDDATA_ERROR
Definition icalerror.h:81
@ ICAL_UNKNOWN_ERROR
Definition icalerror.h:99
@ ICAL_PARSE_ERROR
Definition icalerror.h:84
@ ICAL_UNIMPLEMENTED_ERROR
Definition icalerror.h:96
@ ICAL_USAGE_ERROR
Definition icalerror.h:93
void icalerror_set_error_state(icalerrorenum error, icalerrorstate state)
Sets the icalerrorstate for a given icalerrorenum error.
Definition icalerror.c:221
const char * icalerror_strerror(icalerrorenum e)
Finds the description string for error.
Definition icalerror.c:245
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Definition icalerror.c:118
void icalerror_restore(const char *error, icalerrorstate es)
Definition icalerror.c:212
void icalerror_stop_here(void)
Triggered before any error is called.
Definition icalerror.c:71
icalerrorenum icalerror_error_from_string(const char *str)
Reads an error from a string.
Definition icalerror.c:179
void icalerror_clear_errno(void)
Resets icalerrno to ICAL_NO_ERROR.
Definition icalerror.c:96
icalerrorstate icalerror_supress(const char *error)
Suppresses a given error.
Definition icalerror.c:192