Core: Unify display of error type prefixes

This commit is contained in:
Danil Alexeev 2025-05-05 19:08:19 +03:00
parent 8f87e60307
commit 24494d840e
No known key found for this signature in database
GPG key ID: 5A52F75A8679EC57
13 changed files with 102 additions and 152 deletions

View file

@ -96,10 +96,11 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
} else {
// Fallback if errors happen before OS init or after it's destroyed.
const char *err_details = (p_message && *p_message) ? p_message : p_error;
fprintf(stderr, "ERROR: %s\n at: %s (%s:%i)\n", err_details, p_function, p_file, p_line);
fprintf(stderr, "%s: %s\n at: %s (%s:%i)\n", _error_handler_type_string(p_type), err_details, p_function, p_file, p_line);
}
_global_lock();
ErrorHandlerList *l = error_handler_list;
while (l) {
l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_editor_notify, p_type);
@ -113,18 +114,20 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
// but we don't want to make it noisy by printing lots of file & line info (because it's already
// been printing by a preceding _err_print_error).
void _err_print_error_asap(const String &p_error, ErrorHandlerType p_type) {
const char *err_details = p_error.utf8().get_data();
if (OS::get_singleton()) {
OS::get_singleton()->printerr("ERROR: %s\n", p_error.utf8().get_data());
OS::get_singleton()->printerr("%s: %s\n", _error_handler_type_string(p_type), err_details);
} else {
// Fallback if errors happen before OS init or after it's destroyed.
const char *err_details = p_error.utf8().get_data();
fprintf(stderr, "ERROR: %s\n", err_details);
fprintf(stderr, "%s: %s\n", _error_handler_type_string(p_type), err_details);
}
_global_lock();
ErrorHandlerList *l = error_handler_list;
while (l) {
l->errfunc(l->userdata, "", "", 0, p_error.utf8().get_data(), "", false, p_type);
l->errfunc(l->userdata, "", "", 0, err_details, "", false, p_type);
l = l->next;
}

View file

@ -46,6 +46,20 @@ enum ErrorHandlerType {
ERR_HANDLER_SHADER,
};
constexpr const char *_error_handler_type_string(ErrorHandlerType p_type) {
switch (p_type) {
case ERR_HANDLER_ERROR:
return "ERROR";
case ERR_HANDLER_WARNING:
return "WARNING";
case ERR_HANDLER_SCRIPT:
return "SCRIPT ERROR";
case ERR_HANDLER_SHADER:
return "SHADER ERROR";
}
return "UNKNOWN ERROR";
}
// Pointer to the error handler printing function. Reassign to any function to have errors printed.
// Parameters: userdata, function, file, line, error, explanation, type.
typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, bool p_editor_notify, ErrorHandlerType p_type);