add better error handling to include line and file in error messages

This commit is contained in:
2025-03-04 14:29:58 +01:00
parent 3164fe1661
commit c0bdc6ca17
2 changed files with 19 additions and 11 deletions

View File

@@ -49,11 +49,15 @@ void warn(char const* fmt, ...) {
(void)fprintf(stderr, "\033[93mW: %s\033[0m\n", buf);
}
noreturn void error(gamestatus error_code, char const* fmt, ...) {
char buf[PRINT_BUFFER_SIZE] = {0};
write_args(buf, fmt);
(void)fprintf(stderr, "\033[91mE: %s\033[0m\n", buf);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buf, NULL);
noreturn void i_error(gamestatus error_code, uint32_t ln, char const* fname, char const* fmt, ...) {
char buf1[PRINT_BUFFER_SIZE] = {0};
write_args(buf1, fmt);
char buf2[PRINT_BUFFER_SIZE * 2] = {0};
sprintf(buf2, "%s\n at %s:%u", buf1, fname, ln);
(void)fprintf(stderr, "\033[91mE: %s\033[0m\n", buf2);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buf2, NULL);
// set status, but exit immediately, as code is not allowed to execute beyond this point
set_gamestatus(error_code);