2021-10-31 23:34:08 +01:00
|
|
|
#ifndef ERROR_MACROS_H
|
|
|
|
#define ERROR_MACROS_H
|
|
|
|
|
|
|
|
#include "core/log/logger.h"
|
|
|
|
|
|
|
|
// Based on Godot Engine's error_macros.h
|
|
|
|
// MIT License
|
|
|
|
// Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.
|
|
|
|
// Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define GENERATE_TRAP \
|
|
|
|
__debugbreak(); \
|
|
|
|
/* Avoid warning about control paths */ \
|
|
|
|
for (;;) { \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define GENERATE_TRAP __builtin_trap();
|
|
|
|
#endif
|
|
|
|
|
2021-11-01 19:11:03 +01:00
|
|
|
#define RLOG_TRACE(str) \
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_trace(__FUNCTION__, __FILE__, __LINE__, str);
|
2021-10-31 23:34:08 +01:00
|
|
|
|
2021-11-01 19:11:03 +01:00
|
|
|
#define RLOG_MSG(str) \
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_message(__FUNCTION__, __FILE__, __LINE__, str);
|
2021-10-31 23:34:08 +01:00
|
|
|
|
2021-11-01 19:11:03 +01:00
|
|
|
#define RLOG_WARN(str) \
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_warning(__FUNCTION__, __FILE__, __LINE__, str);
|
2021-10-31 23:34:08 +01:00
|
|
|
|
2021-11-01 19:11:03 +01:00
|
|
|
#define RLOG_ERR(str) \
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, str);
|
2021-10-31 23:34:08 +01:00
|
|
|
|
2022-02-04 10:38:18 +01:00
|
|
|
#define ERR_FAIL_MSG(msg) \
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
|
2022-02-04 10:38:18 +01:00
|
|
|
return;
|
|
|
|
|
2022-02-04 11:32:07 +01:00
|
|
|
#define ERR_FAIL_V_MSG(val, msg) \
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
|
2022-02-04 11:32:07 +01:00
|
|
|
return val;
|
|
|
|
|
2021-10-31 23:34:08 +01:00
|
|
|
#define ERR_FAIL_INDEX(index, size) \
|
|
|
|
if ((index < 0) || (index >= size)) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \
|
2021-10-31 23:34:08 +01:00
|
|
|
return;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
2022-02-04 10:38:18 +01:00
|
|
|
#define ERR_FAIL_INDEX_MSG(index, size, msg) \
|
|
|
|
if ((index < 0) || (index >= size)) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \
|
2022-02-04 10:38:18 +01:00
|
|
|
return;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
2021-10-31 23:34:08 +01:00
|
|
|
#define ERR_FAIL_INDEX_V(index, size, val) \
|
|
|
|
if ((index < 0) || (index >= size)) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \
|
2021-10-31 23:34:08 +01:00
|
|
|
return val;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
2022-02-04 10:38:18 +01:00
|
|
|
#define ERR_FAIL_INDEX_V_MSG(index, size, val, msg) \
|
|
|
|
if ((index < 0) || (index >= size)) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \
|
2022-02-04 10:38:18 +01:00
|
|
|
return val;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
2021-10-31 23:34:08 +01:00
|
|
|
#define ERR_FAIL_COND(cond) \
|
|
|
|
if (cond) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \
|
2021-10-31 23:34:08 +01:00
|
|
|
return;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
2022-02-04 10:38:18 +01:00
|
|
|
#define ERR_FAIL_COND_MSG(cond, msg) \
|
|
|
|
if (cond) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
|
2022-02-04 10:38:18 +01:00
|
|
|
return;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
2021-10-31 23:34:08 +01:00
|
|
|
#define ERR_FAIL_COND_V(cond, val) \
|
|
|
|
if (cond) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \
|
2021-10-31 23:34:08 +01:00
|
|
|
return val;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
2022-02-04 10:38:18 +01:00
|
|
|
#define ERR_FAIL_COND_V_MSG(cond, val, msg) \
|
|
|
|
if (cond) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
|
2022-02-04 10:38:18 +01:00
|
|
|
return val;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
2022-02-04 22:02:54 +01:00
|
|
|
#define ERR_CONTINUE(cond) \
|
|
|
|
if (cond) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_CONTINUE: \"" #cond "\" is true!"); \
|
2022-02-04 22:02:54 +01:00
|
|
|
continue;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
|
|
|
#define ERR_CONTINUE_MSG(cond, msg) \
|
|
|
|
if (cond) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
|
2022-02-04 22:02:54 +01:00
|
|
|
continue;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
|
|
|
#define ERR_CONTINUE_ACTION(cond, action) \
|
|
|
|
if (cond) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_CONTINUE: \"" #cond "\" is true!"); \
|
2022-02-04 22:02:54 +01:00
|
|
|
action;\
|
|
|
|
continue;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
|
|
|
#define ERR_CONTINUE_ACTION_MSG(cond, action, msg) \
|
|
|
|
if (cond) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
|
2022-02-04 22:02:54 +01:00
|
|
|
action;\
|
|
|
|
continue;\
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
2021-10-31 23:34:08 +01:00
|
|
|
#define CRASH_INDEX(index, size) \
|
|
|
|
if ((index < 0) || (index >= size)) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, "CRASH!"); \
|
2021-10-31 23:34:08 +01:00
|
|
|
GENERATE_TRAP \
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
|
|
|
#define CRASH_COND(cond) \
|
|
|
|
if (cond) {\
|
2022-02-15 11:57:44 +01:00
|
|
|
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "CRASH_COND: \"" #cond "\" is true!"); \
|
2021-10-31 23:34:08 +01:00
|
|
|
GENERATE_TRAP \
|
|
|
|
} else\
|
|
|
|
((void)0)\
|
|
|
|
|
|
|
|
#endif
|