config error reporting

Try to handle the convoluted error handling better.  Not very
thoroughly tested...
This commit is contained in:
PatR
2021-05-21 08:52:18 -07:00
parent 164417f01f
commit 0e9bf2e03c
2 changed files with 14 additions and 15 deletions

View File

@@ -690,7 +690,7 @@ fix globby_bill_fixup to use shopkeeper instead of Null for glob pricing
applying a book to check readability treated novels as if they were spellbooks
#version was leaving the 'in_lua' flag set and if subsequent 'O' issued an
error (example was an attempt to interactively set bouldersym to an
invalid value), the error routine reporting crashed via segfault
invalid value), the error reporting routine crashed via segfault
curses: 'msg_window' option wasn't functional for curses unless the binary
also included tty support

View File

@@ -2837,7 +2837,7 @@ void
config_error_init(boolean from_file, const char *sourcename, boolean secure)
{
struct _config_error_frame *tmp = (struct _config_error_frame *)
alloc(sizeof (struct _config_error_frame));
alloc(sizeof *tmp);
tmp->line_num = 0;
tmp->num_errors = 0;
@@ -2913,6 +2913,14 @@ config_erradd(const char *buf)
if (!buf || !*buf)
buf = "Unknown error";
if (!g.program_state.config_error_ready) {
/* either very early, where pline() will use raw_print(), or
player gave bad value when prompted by interactive 'O' command */
pline("%s%s.", !iflags.window_inited ? "config_error_add: " : "", buf);
wait_synch();
return;
}
if (iflags.in_lua) {
struct _config_error_errmsg *dat
= (struct _config_error_errmsg *) alloc(sizeof *dat);
@@ -2924,14 +2932,6 @@ config_erradd(const char *buf)
return;
}
if (!config_error_data) {
/* either very early, where pline() will use raw_print(), or
player gave bad value when prompted by interactive 'O' command */
pline("%s%s.", !iflags.window_inited ? "config_error_add: " : "", buf);
wait_synch();
return;
}
config_error_data->num_errors++;
if (!config_error_data->origline_shown && !config_error_data->secure) {
pline("\n%s", config_error_data->origline);
@@ -2956,15 +2956,14 @@ config_error_done(void)
return 0;
n = config_error_data->num_errors;
if (n) {
pline("\n%d error%s in %s.\n", n,
(n > 1) ? "s" : "",
*config_error_data->source
? config_error_data->source : configfile);
pline("\n%d error%s in %s.\n", n, plur(n),
*config_error_data->source ? config_error_data->source
: configfile);
wait_synch();
}
config_error_data = tmp->next;
free(tmp);
g.program_state.config_error_ready = FALSE;
g.program_state.config_error_ready = (config_error_data != 0);
return n;
}