summaryrefslogtreecommitdiffstats
path: root/core/error_macros.h
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2019-11-11 13:27:51 +0100
committerGitHub <noreply@github.com>2019-11-11 13:27:51 +0100
commit6b1628f9fcc50dc16af08c2b87f27108ff6e15c5 (patch)
tree5bb1ef20e714dc1d9a8421ee2419036534d2f230 /core/error_macros.h
parent5c038acdc159708113fdc911c44abf1d6dcdbdf7 (diff)
parent83069a3c0f01507acd24672c90b24c9eba868aba (diff)
downloadredot-engine-6b1628f9fcc50dc16af08c2b87f27108ff6e15c5.tar.gz
Merge pull request #33517 from madmiraal/fix-_MSG-macros
Send *_MSG macros' explanations directly to the _err_print_error().
Diffstat (limited to 'core/error_macros.h')
-rw-r--r--core/error_macros.h255
1 files changed, 97 insertions, 158 deletions
diff --git a/core/error_macros.h b/core/error_macros.h
index d4b69ff40d..6d17fd2cb5 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -57,9 +57,6 @@ enum ErrorHandlerType {
class String;
typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
-void _err_set_last_error(const char *p_err);
-void _err_set_last_error(const String &p_err);
-void _err_clear_last_error();
struct ErrorHandlerList {
@@ -80,7 +77,12 @@ void remove_error_handler(ErrorHandlerList *p_handler);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
-void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, bool fatal = false);
+void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
+void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const char *p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
+void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const String &p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
+void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const String &p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
+void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message = "", bool fatal = false);
+void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool fatal = false);
#ifndef _STR
#define _STR(m_x) #m_x
@@ -91,29 +93,6 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
/** An index has failed if m_index<0 or m_index >=m_size, the function exits */
-extern bool _err_error_exists;
-
-#ifdef DEBUG_ENABLED
-/** Print a warning string.
- */
-#define ERR_EXPLAINC(m_reason) \
- { \
- _err_set_last_error(m_reason); \
- _err_error_exists = true; \
- }
-#define ERR_EXPLAIN(m_string) \
- { \
- _err_set_last_error(m_string); \
- _err_error_exists = true; \
- }
-
-#else
-
-#define ERR_EXPLAIN(m_text)
-#define ERR_EXPLAINC(m_text)
-
-#endif
-
#ifdef __GNUC__
//#define FUNCTION_STR __PRETTY_FUNCTION__ - too annoying
#define FUNCTION_STR __FUNCTION__
@@ -140,17 +119,14 @@ extern bool _err_error_exists;
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return; \
} \
- _err_error_exists = false; \
} while (0); // (*)
-#define ERR_FAIL_INDEX_MSG(m_index, m_size, m_msg) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
- return; \
- } \
- _err_error_exists = false; \
+#define ERR_FAIL_INDEX_MSG(m_index, m_size, m_msg) \
+ do { \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
+ return; \
+ } \
} while (0); // (*)
/** An index has failed if m_index<0 or m_index >=m_size, the function exits.
@@ -164,17 +140,14 @@ extern bool _err_error_exists;
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} \
- _err_error_exists = false; \
} while (0); // (*)
-#define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
- return m_retval; \
- } \
- _err_error_exists = false; \
+#define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
+ do { \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
+ return m_retval; \
+ } \
} while (0); // (*)
/** An index has failed if m_index >=m_size, the function exits.
@@ -188,37 +161,33 @@ extern bool _err_error_exists;
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} \
- _err_error_exists = false; \
} while (0); // (*)
-#define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
- do { \
- if (unlikely((m_index) >= (m_size))) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
- return m_retval; \
- } \
- _err_error_exists = false; \
+#define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
+ do { \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
+ return m_retval; \
+ } \
} while (0); // (*)
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
* We'll return a null reference and try to keep running.
*/
-#define CRASH_BAD_INDEX(m_index, m_size) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), true); \
- GENERATE_TRAP \
- } \
+#define CRASH_BAD_INDEX(m_index, m_size) \
+ do { \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
+ GENERATE_TRAP \
+ } \
} while (0); // (*)
-#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), true); \
- GENERATE_TRAP \
- } \
+#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
+ do { \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \
+ GENERATE_TRAP \
+ } \
} while (0); // (*)
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@@ -231,17 +200,14 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
return; \
} \
- _err_error_exists = false; \
}
-#define ERR_FAIL_NULL_MSG(m_param, m_msg) \
- { \
- if (unlikely(!m_param)) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
- return; \
- } \
- _err_error_exists = false; \
+#define ERR_FAIL_NULL_MSG(m_param, m_msg) \
+ { \
+ if (unlikely(!m_param)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null.", m_msg); \
+ return; \
+ } \
}
#define ERR_FAIL_NULL_V(m_param, m_retval) \
@@ -250,17 +216,14 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
return m_retval; \
} \
- _err_error_exists = false; \
}
-#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
- { \
- if (unlikely(!m_param)) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
- return m_retval; \
- } \
- _err_error_exists = false; \
+#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
+ { \
+ if (unlikely(!m_param)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null.", m_msg); \
+ return m_retval; \
+ } \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@@ -273,17 +236,14 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true."); \
return; \
} \
- _err_error_exists = false; \
}
-#define ERR_FAIL_COND_MSG(m_cond, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true."); \
- return; \
- } \
- _err_error_exists = false; \
+#define ERR_FAIL_COND_MSG(m_cond, m_msg) \
+ { \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true.", m_msg); \
+ return; \
+ } \
}
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
@@ -297,13 +257,12 @@ extern bool _err_error_exists;
} \
}
-#define CRASH_COND_MSG(m_cond, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition ' " _STR(m_cond) " ' is true."); \
- GENERATE_TRAP \
- } \
+#define CRASH_COND_MSG(m_cond, m_msg) \
+ { \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition ' " _STR(m_cond) " ' is true.", m_msg); \
+ GENERATE_TRAP \
+ } \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@@ -318,17 +277,14 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval)); \
return m_retval; \
} \
- _err_error_exists = false; \
}
-#define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval)); \
- return m_retval; \
- } \
- _err_error_exists = false; \
+#define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
+ { \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval), m_msg); \
+ return m_retval; \
+ } \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@@ -341,17 +297,14 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:"); \
continue; \
} \
- _err_error_exists = false; \
}
-#define ERR_CONTINUE_MSG(m_cond, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:"); \
- continue; \
- } \
- _err_error_exists = false; \
+#define ERR_CONTINUE_MSG(m_cond, m_msg) \
+ { \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:", m_msg); \
+ continue; \
+ } \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@@ -364,17 +317,14 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
break; \
} \
- _err_error_exists = false; \
}
-#define ERR_BREAK_MSG(m_cond, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
- break; \
- } \
- _err_error_exists = false; \
+#define ERR_BREAK_MSG(m_cond, m_msg) \
+ { \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:", m_msg); \
+ break; \
+ } \
}
/** Print an error string and return
@@ -383,14 +333,13 @@ extern bool _err_error_exists;
#define ERR_FAIL() \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed."); \
- _err_error_exists = false; \
return; \
}
-#define ERR_FAIL_MSG(m_msg) \
- { \
- ERR_EXPLAIN(m_msg); \
- ERR_FAIL(); \
+#define ERR_FAIL_MSG(m_msg) \
+ { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed.", m_msg); \
+ return; \
}
/** Print an error string and return with value
@@ -399,14 +348,13 @@ extern bool _err_error_exists;
#define ERR_FAIL_V(m_value) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value)); \
- _err_error_exists = false; \
return m_value; \
}
-#define ERR_FAIL_V_MSG(m_value, m_msg) \
- { \
- ERR_EXPLAIN(m_msg); \
- ERR_FAIL_V(m_value); \
+#define ERR_FAIL_V_MSG(m_value, m_msg) \
+ { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value), m_msg); \
+ return m_value; \
}
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
@@ -418,10 +366,10 @@ extern bool _err_error_exists;
GENERATE_TRAP \
}
-#define CRASH_NOW_MSG(m_msg) \
- { \
- ERR_EXPLAIN(m_msg); \
- CRASH_NOW(); \
+#define CRASH_NOW_MSG(m_msg) \
+ { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method/Function Failed.", m_msg); \
+ GENERATE_TRAP \
}
/** Print an error string.
@@ -430,13 +378,11 @@ extern bool _err_error_exists;
#define ERR_PRINT(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
- _err_error_exists = false; \
}
#define ERR_PRINTS(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
- _err_error_exists = false; \
}
#define ERR_PRINT_ONCE(m_string) \
@@ -444,7 +390,6 @@ extern bool _err_error_exists;
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
- _err_error_exists = false; \
first_print = false; \
} \
}
@@ -455,13 +400,11 @@ extern bool _err_error_exists;
#define WARN_PRINT(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
- _err_error_exists = false; \
}
#define WARN_PRINTS(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
- _err_error_exists = false; \
}
#define WARN_PRINT_ONCE(m_string) \
@@ -469,7 +412,6 @@ extern bool _err_error_exists;
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
- _err_error_exists = false; \
first_print = false; \
} \
}
@@ -479,20 +421,17 @@ extern bool _err_error_exists;
static volatile bool warning_shown = false; \
if (!warning_shown) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future", ERR_HANDLER_WARNING); \
- _err_error_exists = false; \
warning_shown = true; \
} \
}
-#define WARN_DEPRECATED_MSG(m_msg) \
- { \
- static volatile bool warning_shown = false; \
- if (!warning_shown) { \
- ERR_EXPLAIN(m_msg); \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future", ERR_HANDLER_WARNING); \
- _err_error_exists = false; \
- warning_shown = true; \
- } \
+#define WARN_DEPRECATED_MSG(m_msg) \
+ { \
+ static volatile bool warning_shown = false; \
+ if (!warning_shown) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future", m_msg, ERR_HANDLER_WARNING); \
+ warning_shown = true; \
+ } \
}
#endif