| | @@ -1026,14 +1026,49 @@ |
| 1026 | 1026 | ** The following variable becomes true while processing a fatal error |
| 1027 | 1027 | ** or a panic. If additional "recursive-fatal" errors occur while |
| 1028 | 1028 | ** shutting down, the recursive errors are silently ignored. |
| 1029 | 1029 | */ |
| 1030 | 1030 | static int mainInFatalError = 0; |
| 1031 | + |
| 1032 | +/* |
| 1033 | +** Write error message output |
| 1034 | +*/ |
| 1035 | +static int fossil_print_error(int rc, const char *z){ |
| 1036 | +#ifdef FOSSIL_ENABLE_JSON |
| 1037 | + if( g.json.isJsonMode ){ |
| 1038 | + json_err( 0, z, 1 ); |
| 1039 | + if( g.isHTTP ){ |
| 1040 | + rc = 0 /* avoid HTTP 500 */; |
| 1041 | + } |
| 1042 | + } |
| 1043 | + else |
| 1044 | +#endif |
| 1045 | + if( g.cgiOutput==1 && g.db ){ |
| 1046 | + g.cgiOutput = 2; |
| 1047 | + cgi_reset_content(); |
| 1048 | + cgi_set_content_type("text/html"); |
| 1049 | + style_header("Bad Request"); |
| 1050 | + @ <p class="generalError">%h(z)</p> |
| 1051 | + cgi_set_status(400, "Bad Request"); |
| 1052 | + style_footer(); |
| 1053 | + cgi_reply(); |
| 1054 | + }else if( !g.fQuiet ){ |
| 1055 | + fossil_force_newline(); |
| 1056 | + fossil_trace("%s\n", z); |
| 1057 | + } |
| 1058 | + return rc; |
| 1059 | +} |
| 1031 | 1060 | |
| 1032 | 1061 | /* |
| 1033 | 1062 | ** Print an error message, rollback all databases, and quit. These |
| 1034 | 1063 | ** routines never return. |
| 1064 | +** |
| 1065 | +** Use fossil_fatal() for malformed inputs that should be reported back |
| 1066 | +** to the user, but which do not represent a configuration problem or bug. |
| 1067 | +** |
| 1068 | +** Use fossil_panic() for any kind of error that should be brought to the |
| 1069 | +** attention of the system administrator. |
| 1035 | 1070 | */ |
| 1036 | 1071 | NORETURN void fossil_panic(const char *zFormat, ...){ |
| 1037 | 1072 | va_list ap; |
| 1038 | 1073 | int rc = 1; |
| 1039 | 1074 | char z[1000]; |
| | @@ -1045,67 +1080,22 @@ |
| 1045 | 1080 | db_force_rollback(); |
| 1046 | 1081 | va_start(ap, zFormat); |
| 1047 | 1082 | sqlite3_vsnprintf(sizeof(z),z,zFormat, ap); |
| 1048 | 1083 | va_end(ap); |
| 1049 | 1084 | fossil_errorlog("panic: %s", z); |
| 1050 | | -#ifdef FOSSIL_ENABLE_JSON |
| 1051 | | - if( g.json.isJsonMode ){ |
| 1052 | | - json_err( 0, z, 1 ); |
| 1053 | | - if( g.isHTTP ){ |
| 1054 | | - rc = 0 /* avoid HTTP 500 */; |
| 1055 | | - } |
| 1056 | | - } |
| 1057 | | - else |
| 1058 | | -#endif |
| 1059 | | - { |
| 1060 | | - if( g.cgiOutput ){ |
| 1061 | | - cgi_printf("<p class=\"generalError\">%h</p>", z); |
| 1062 | | - cgi_set_status(500, "Internal Server Error"); |
| 1063 | | - cgi_reply(); |
| 1064 | | - }else if( !g.fQuiet ){ |
| 1065 | | - fossil_force_newline(); |
| 1066 | | - fossil_puts("Fossil internal error: ", 1); |
| 1067 | | - fossil_puts(z, 1); |
| 1068 | | - fossil_puts("\n", 1); |
| 1069 | | - } |
| 1070 | | - } |
| 1085 | + rc = fossil_print_error(rc, z); |
| 1071 | 1086 | exit(rc); |
| 1072 | 1087 | } |
| 1073 | | - |
| 1074 | 1088 | NORETURN void fossil_fatal(const char *zFormat, ...){ |
| 1075 | 1089 | char *z; |
| 1076 | 1090 | int rc = 1; |
| 1077 | 1091 | va_list ap; |
| 1078 | 1092 | mainInFatalError = 1; |
| 1079 | 1093 | va_start(ap, zFormat); |
| 1080 | 1094 | z = vmprintf(zFormat, ap); |
| 1081 | 1095 | va_end(ap); |
| 1082 | | - fossil_errorlog("fatal: %s", z); |
| 1083 | | -#ifdef FOSSIL_ENABLE_JSON |
| 1084 | | - if( g.json.isJsonMode ){ |
| 1085 | | - json_err( g.json.resultCode, z, 1 ); |
| 1086 | | - if( g.isHTTP ){ |
| 1087 | | - rc = 0 /* avoid HTTP 500 */; |
| 1088 | | - } |
| 1089 | | - } |
| 1090 | | - else |
| 1091 | | -#endif |
| 1092 | | - { |
| 1093 | | - if( g.cgiOutput==1 && g.db ){ |
| 1094 | | - g.cgiOutput = 2; |
| 1095 | | - cgi_reset_content(); |
| 1096 | | - cgi_set_content_type("text/html"); |
| 1097 | | - style_header("Bad Request"); |
| 1098 | | - @ <p class="generalError">%h(z)</p> |
| 1099 | | - cgi_set_status(400, "Bad Request"); |
| 1100 | | - style_footer(); |
| 1101 | | - cgi_reply(); |
| 1102 | | - }else if( !g.fQuiet ){ |
| 1103 | | - fossil_force_newline(); |
| 1104 | | - fossil_trace("%s\n", z); |
| 1105 | | - } |
| 1106 | | - } |
| 1096 | + rc = fossil_print_error(rc, z); |
| 1107 | 1097 | fossil_free(z); |
| 1108 | 1098 | db_force_rollback(); |
| 1109 | 1099 | fossil_exit(rc); |
| 1110 | 1100 | } |
| 1111 | 1101 | |
| | @@ -1125,36 +1115,24 @@ |
| 1125 | 1115 | if( mainInFatalError ) return; |
| 1126 | 1116 | mainInFatalError = 1; |
| 1127 | 1117 | va_start(ap, zFormat); |
| 1128 | 1118 | z = vmprintf(zFormat, ap); |
| 1129 | 1119 | va_end(ap); |
| 1130 | | - fossil_errorlog("fatal: %s", z); |
| 1131 | | -#ifdef FOSSIL_ENABLE_JSON |
| 1132 | | - if( g.json.isJsonMode ){ |
| 1133 | | - json_err( g.json.resultCode, z, 1 ); |
| 1134 | | - if( g.isHTTP ){ |
| 1135 | | - rc = 0 /* avoid HTTP 500 */; |
| 1136 | | - } |
| 1137 | | - } else |
| 1138 | | -#endif |
| 1139 | | - { |
| 1140 | | - if( g.cgiOutput ){ |
| 1141 | | - g.cgiOutput = 0; |
| 1142 | | - cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z); |
| 1143 | | - cgi_set_status(400, "Bad Request"); |
| 1144 | | - cgi_reply(); |
| 1145 | | - }else{ |
| 1146 | | - fossil_force_newline(); |
| 1147 | | - fossil_trace("%s\n", z); |
| 1148 | | - } |
| 1149 | | - } |
| 1120 | + rc = fossil_print_error(rc, z); |
| 1150 | 1121 | db_force_rollback(); |
| 1151 | 1122 | fossil_exit(rc); |
| 1152 | 1123 | } |
| 1153 | 1124 | |
| 1154 | 1125 | |
| 1155 | | -/* Print a warning message */ |
| 1126 | +/* Print a warning message. |
| 1127 | +** |
| 1128 | +** Unlike fossil_fatal() and fossil_panic(), this routine does return |
| 1129 | +** and processing attempts to continue. A message is written to the |
| 1130 | +** error log, however, so this routine should only be used for situations |
| 1131 | +** that require administrator or developer attention. Minor problems |
| 1132 | +** in user inputs should not use this routine. |
| 1133 | +*/ |
| 1156 | 1134 | void fossil_warning(const char *zFormat, ...){ |
| 1157 | 1135 | char *z; |
| 1158 | 1136 | va_list ap; |
| 1159 | 1137 | va_start(ap, zFormat); |
| 1160 | 1138 | z = vmprintf(zFormat, ap); |
| 1161 | 1139 | |