From 86727730b8e4cfce2a4ecf2e787c8bf7f57af924 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Wed, 1 Jul 2020 08:07:18 +0200 Subject: Improve line/error reporting in server config parsing --- minecctl/misc-commands.c | 5 +++-- minecctl/server.c | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'minecctl') diff --git a/minecctl/misc-commands.c b/minecctl/misc-commands.c index f7f2dea..a4188f9 100644 --- a/minecctl/misc-commands.c +++ b/minecctl/misc-commands.c @@ -20,6 +20,7 @@ bool do_list(struct cfg *cfg) bool do_lint(struct cfg *cfg) { struct server *server; + const char *error; bool rv = true; /* server->scfg.filename check excludes servers created from cmdline */ @@ -32,8 +33,8 @@ bool do_lint(struct cfg *cfg) /* FIXME: should return bool */ server_read_config(cfg, server); - if (!scfg_validate(&server->scfg)) { - error("%s: invalid", server->name); + if (!scfg_validate(&server->scfg, &error)) { + error("%s: invalid (%s)", server->name, error); rv = false; } } diff --git a/minecctl/server.c b/minecctl/server.c index 21df7f4..658254f 100644 --- a/minecctl/server.c +++ b/minecctl/server.c @@ -10,6 +10,8 @@ void server_read_config(struct cfg *cfg, struct server *server) { + unsigned lineno; + const char *error; char buf[4096]; size_t off = 0; ssize_t r; @@ -47,8 +49,9 @@ void server_read_config(struct cfg *cfg, struct server *server) buf[off] = '\0'; close(fd); - if (!scfg_parse(&server->scfg, buf, NULL)) - die("Unable to parse %s", server->scfg.filename); + if (!scfg_parse(&server->scfg, buf, NULL, &lineno, &error)) + die("Unable to parse %s, line %u: %s", server->scfg.filename, + lineno, error); if (!server->scfg.rcon_password) verbose("rcon password not found in %s", server->scfg.filename); -- cgit v1.2.3