summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorMarcel Admiraal <madmiraal@users.noreply.github.com>2019-11-10 07:44:31 +0100
committerMarcel Admiraal <madmiraal@users.noreply.github.com>2019-11-10 08:03:54 +0100
commitb7fdac60f16cef462a8ef97ce8c77308ba38a62f (patch)
tree8cb150efd7b82c315f7614b16879184656205155 /core
parent94f00eb6c5323dff933a4985b60e8ebf9391f940 (diff)
Send m_msg directly to _err_print_error().
Diffstat (limited to 'core')
-rw-r--r--core/error_macros.cpp35
-rw-r--r--core/error_macros.h223
2 files changed, 142 insertions, 116 deletions
diff --git a/core/error_macros.cpp b/core/error_macros.cpp
index eda6b9cbbb..71517a47ec 100644
--- a/core/error_macros.cpp
+++ b/core/error_macros.cpp
@@ -109,9 +109,40 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
_err_print_error(p_function, p_file, p_line, p_error.utf8().get_data(), p_type);
}
-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) {
+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) {
+
+ OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, p_message, (Logger::ErrorType)p_type);
+
+ _global_lock();
+ ErrorHandlerList *l = error_handler_list;
+ while (l) {
+
+ l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_type);
+ l = l->next;
+ }
+
+ _global_unlock();
+}
+
+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_print_error(p_function, p_file, p_line, p_error.utf8().get_data(), p_message, p_type);
+}
+
+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_print_error(p_function, p_file, p_line, p_error, p_message.utf8().get_data(), p_type);
+}
+
+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_print_error(p_function, p_file, p_line, p_error.utf8().get_data(), p_message.utf8().get_data(), p_type);
+}
+
+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) {
String fstr(fatal ? "FATAL: " : "");
String err(fstr + "Index " + p_index_str + "=" + itos(p_index) + " out of size (" + p_size_str + "=" + itos(p_size) + ")");
- _err_print_error(p_function, p_file, p_line, err.utf8().get_data());
+ _err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message);
+}
+
+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) {
+ _err_print_index_error(p_function, p_file, p_line, p_index, p_size, p_index_str, p_size_str, p_message.utf8().get_data(), fatal);
}
diff --git a/core/error_macros.h b/core/error_macros.h
index d4b69ff40d..66bbf003c9 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -80,7 +80,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
@@ -143,14 +148,13 @@ extern bool _err_error_exists;
_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; \
+ } \
+ _err_error_exists = false; \
} while (0); // (*)
/** An index has failed if m_index<0 or m_index >=m_size, the function exits.
@@ -167,14 +171,13 @@ extern bool _err_error_exists;
_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; \
+ } \
+ _err_error_exists = false; \
} while (0); // (*)
/** An index has failed if m_index >=m_size, the function exits.
@@ -191,34 +194,32 @@ extern bool _err_error_exists;
_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; \
+ } \
+ _err_error_exists = false; \
} 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().
@@ -234,14 +235,13 @@ extern bool _err_error_exists;
_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; \
+ } \
+ _err_error_exists = false; \
}
#define ERR_FAIL_NULL_V(m_param, m_retval) \
@@ -253,14 +253,13 @@ extern bool _err_error_exists;
_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; \
+ } \
+ _err_error_exists = false; \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@@ -276,14 +275,13 @@ extern bool _err_error_exists;
_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; \
+ } \
+ _err_error_exists = false; \
}
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
@@ -297,13 +295,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().
@@ -321,14 +318,13 @@ extern bool _err_error_exists;
_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; \
+ } \
+ _err_error_exists = false; \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@@ -344,14 +340,13 @@ extern bool _err_error_exists;
_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; \
+ } \
+ _err_error_exists = false; \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@@ -367,14 +362,13 @@ extern bool _err_error_exists;
_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; \
+ } \
+ _err_error_exists = false; \
}
/** Print an error string and return
@@ -387,10 +381,11 @@ extern bool _err_error_exists;
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); \
+ _err_error_exists = false; \
+ return; \
}
/** Print an error string and return with value
@@ -403,10 +398,11 @@ extern bool _err_error_exists;
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); \
+ _err_error_exists = false; \
+ return m_value; \
}
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
@@ -418,10 +414,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.
@@ -484,15 +480,14 @@ extern bool _err_error_exists;
} \
}
-#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); \
+ _err_error_exists = false; \
+ warning_shown = true; \
+ } \
}
#endif