Skip to content

Commit

Permalink
Rework error printing
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Jun 10, 2024
1 parent b028846 commit 57551a3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions common/error.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ import core.stdc.stdlib : malloc;
extern (C):

void print_error(const(char) *message,
const(char)* prefix = null,
const(char)* mod = cast(char*)__MODULE__,
int line = __LINE__) {
debug {
printf("[%s@%d] ", mod, line);
}
printf("error: %s\n", message);
fputs("error: ", stderr);
if (prefix) {
fputs(prefix, stderr);
fputs(": ", stderr);
}
fputs(message, stderr);
fputs("\n", stderr);
}
void print_error_adbg(
const(char)* mod = cast(char*)__FILE__,
Expand All @@ -39,15 +46,14 @@ void print_error_adbg(
printf("[%s@%d] ", mod, line);
}
const(adbg_error_t)* e = adbg_error_current();
print_error(adbg_error_message(), e.mod, e.line);
print_error(adbg_error_message(), null, e.mod, e.line);
}

void panic(int code, const(char)* message,
const(char)* prefix = null,
const(char)* mod = cast(char*)__MODULE__,
int line = __LINE__) {
if (prefix) printf("%s: ", prefix);
print_error(message, mod, line);
print_error(message, prefix, mod, line);
exit(code);
}
void panic_crt(const(char)* prefix = null,
Expand Down

0 comments on commit 57551a3

Please sign in to comment.