From a20acf4031c9207f895c7ae6e04c3f75f90a2774 Mon Sep 17 00:00:00 2001 From: Steins7 Date: Sat, 20 Apr 2024 15:20:18 +0200 Subject: [PATCH] Implement error header --- srv/error.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 srv/error.h diff --git a/srv/error.h b/srv/error.h new file mode 100644 index 0000000..2616e6b --- /dev/null +++ b/srv/error.h @@ -0,0 +1,50 @@ +/** @file error.h + * Module providing error handling macros + * + * The module implements the assert macro intended to allow catching critical + * errors during debug while having no influence in the release code as well as + * multiple tool macros to handles other kinds of errors + */ + +#ifndef _ERROR_H_ +#define _ERROR_H_ + +//--includes-------------------------------------------------------------------- + +#include "debug.h" + +#define ERROR_ASSERT 1 + + +//--type definitions------------------------------------------------------------ + +#define error_to_string(arg) #arg + +#if ERROR_ASSERT +#define error_assert(cond) \ + do { \ + if (!(cond)) { \ + debug_error("%s:l%u:%s: %s", __FILE__, __LINE__, __func__, \ + error_to_string(cond)); \ + while (true) {} \ + } \ + } while (0) +#else +#define error_assert(cond) do {} while (0) +#endif + +#if ERROR_ASSERT +#define error_trigger(msg, ...) \ + do { \ + debug_error(msg __VA_OPT__(,) __VA_ARGS__); \ + while (true) {} \ + } while (0) +#else +#define error_trigger(msg) do {} while (0) +#endif + + +//--functions------------------------------------------------------------------- + +#endif //_ERROR_H_ +