Display error type (error, warning, script error) in OS::print_error

Previously all types of errors would be shown as ERROR, thus making for example warnings (WARN_PRINT) somewhat aggressive.
ERROR is displayed in red, WARNING in yellow and SCRIPT ERROR in magenta (though the latter does not seem used so far).
Fixes #1127.
This commit is contained in:
Rémi Verschelde 2015-11-05 20:13:05 +01:00
parent dde6396f22
commit 6334895088
4 changed files with 63 additions and 25 deletions

View file

@ -61,9 +61,16 @@ void OS::debug_break() {
void OS::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) {
const char* err_type;
switch(p_type) {
case ERR_ERROR: err_type="**ERROR**"; break;
case ERR_WARNING: err_type="**WARNING**"; break;
case ERR_SCRIPT: err_type="**SCRIPT ERROR**"; break;
}
if (p_rationale && *p_rationale)
print("**ERROR**: %s\n ",p_rationale);
print("**ERROR**: At: %s:%i:%s() - %s\n",p_file,p_line,p_function,p_code);
print("%s: %s\n ",err_type,p_rationale);
print("%s: At: %s:%i:%s() - %s\n",err_type,p_file,p_line,p_function,p_code);
}
void OS::print(const char* p_format, ...) {

View file

@ -65,15 +65,25 @@ void OS_Unix::print_error(const char* p_function,const char* p_file,int p_line,c
if (!_print_error_enabled)
return;
if (p_rationale && p_rationale[0]) {
const char* err_details;
if (p_rationale && p_rationale[0])
err_details=p_rationale;
else
err_details=p_code;
print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_rationale);
switch(p_type) {
case ERR_ERROR:
print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,err_details);
print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
} else {
print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_code);
print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
break;
case ERR_WARNING:
print("\E[1;33;40mWARNING: %s: \E[1;37;40m%s\n",p_function,err_details);
print("\E[0;33;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
break;
case ERR_SCRIPT:
print("\E[1;35;40mSCRIPT ERROR: %s: \E[1;37;40m%s\n",p_function,err_details);
print("\E[0;35;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
break;
}
}

View file

@ -1768,15 +1768,26 @@ void OS_Windows::print_error(const char* p_function,const char* p_file,int p_lin
HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
if (!hCon || hCon==INVALID_HANDLE_VALUE) {
if (p_rationale && p_rationale[0]) {
print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_rationale);
const char* err_details;
if (p_rationale && p_rationale[0])
err_details=p_rationale;
else
err_details=p_code;
switch(p_type) {
case ERR_ERROR:
print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,err_details);
print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
} else {
print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_code);
print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
break;
case ERR_WARNING:
print("\E[1;33;40mWARNING: %s: \E[1;37;40m%s\n",p_function,err_details);
print("\E[0;33;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
break;
case ERR_SCRIPT:
print("\E[1;35;40mSCRIPT ERROR: %s: \E[1;37;40m%s\n",p_function,err_details);
print("\E[0;35;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
break;
}
} else {

View file

@ -424,15 +424,25 @@ void OSWinrt::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) con
void OSWinrt::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) {
if (p_rationale && p_rationale[0]) {
const char* err_details;
if (p_rationale && p_rationale[0])
err_details=p_rationale;
else
err_details=p_code;
print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_rationale);
switch(p_type) {
case ERR_ERROR:
print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,err_details);
print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
} else {
print("\E[1;31;40mERROR: %s: \E[1;37;40m%s\n",p_function,p_code);
print("\E[0;31;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
break;
case ERR_WARNING:
print("\E[1;33;40mWARNING: %s: \E[1;37;40m%s\n",p_function,err_details);
print("\E[0;33;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
break;
case ERR_SCRIPT:
print("\E[1;35;40mSCRIPT ERROR: %s: \E[1;37;40m%s\n",p_function,err_details);
print("\E[0;35;40m At: %s:%i.\E[0;0;37m\n",p_file,p_line);
break;
}
}