diff --git a/core/error_macros.h b/core/error_macros.h index fd3a6c6..4ed5add 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -31,6 +31,10 @@ #define RLOG_ERR(str) \ Logger::log_error(str); +#define ERR_FAIL_MSG(msg) \ + Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, msg); \ + return; + #define ERR_FAIL_INDEX(index, size) \ if ((index < 0) || (index >= size)) {\ Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \ @@ -38,6 +42,13 @@ } else\ ((void)0)\ +#define ERR_FAIL_INDEX_MSG(index, size, msg) \ + if ((index < 0) || (index >= size)) {\ + Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \ + return;\ + } else\ + ((void)0)\ + #define ERR_FAIL_INDEX_V(index, size, val) \ if ((index < 0) || (index >= size)) {\ Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \ @@ -45,6 +56,13 @@ } else\ ((void)0)\ +#define ERR_FAIL_INDEX_V_MSG(index, size, val, msg) \ + if ((index < 0) || (index >= size)) {\ + Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \ + return val;\ + } else\ + ((void)0)\ + #define ERR_FAIL_COND(cond) \ if (cond) {\ Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \ @@ -52,6 +70,13 @@ } else\ ((void)0)\ +#define ERR_FAIL_COND_MSG(cond, msg) \ + if (cond) {\ + Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, msg); \ + return;\ + } else\ + ((void)0)\ + #define ERR_FAIL_COND_V(cond, val) \ if (cond) {\ Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \ @@ -59,6 +84,13 @@ } else\ ((void)0)\ +#define ERR_FAIL_COND_V_MSG(cond, val, msg) \ + if (cond) {\ + Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, msg); \ + return val;\ + } else\ + ((void)0)\ + #define CRASH_INDEX(index, size) \ if ((index < 0) || (index >= size)) {\ Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, "CRASH!"); \ diff --git a/core/log/logger.cpp b/core/log/logger.cpp index dd0f281..3bdfb89 100644 --- a/core/log/logger.cpp +++ b/core/log/logger.cpp @@ -44,6 +44,10 @@ void Logger::_log_error(const char *p_function, const char *p_file, int p_line, { printf("!ERROR: (%s) %s:%d. %s\n", p_file, p_function, p_line, str); } +void Logger::_log_error(const char *p_function, const char *p_file, int p_line, const String &str) +{ + printf("!ERROR: (%s) %s:%d. %s\n", p_file, p_function, p_line, str.c_str()); +} void Logger::_log_msg_error(const char *p_function, const char *p_file, int p_line, const char *p_msg, const char *str) { printf("!ERROR: (%s) %s:%d :: %s. %s\n", p_file, p_function, p_line, str, p_msg); diff --git a/core/log/logger.h b/core/log/logger.h index 7c21771..cef8eeb 100644 --- a/core/log/logger.h +++ b/core/log/logger.h @@ -18,6 +18,7 @@ public: static void log_error(const char *str); static void _log_error(const char *p_function, const char *p_file, int p_line, const char *str); + static void _log_error(const char *p_function, const char *p_file, int p_line, const String &str); static void _log_msg_error(const char *p_function, const char *p_file, int p_line, const char *p_msg, const char *str); static void _log_index_error(const char *p_function, const char *p_file, int p_line, const int index, const int size, const char *str); };