diff --git a/server/core/modulecmd.cc b/server/core/modulecmd.cc index d8c96f55f..e2c3fab14 100644 --- a/server/core/modulecmd.cc +++ b/server/core/modulecmd.cc @@ -541,6 +541,12 @@ void modulecmd_arg_free(MODULECMD_ARG* arg) } } +static void modulecmd_clear_error() +{ + prepare_error(); + errbuf[0] = '\0'; +} + bool modulecmd_call_command(const MODULECMD *cmd, const MODULECMD_ARG *args, json_t** output) { bool rval = false; @@ -557,6 +563,8 @@ bool modulecmd_call_command(const MODULECMD *cmd, const MODULECMD_ARG *args, jso args = &MODULECMD_NO_ARGUMENTS; } + modulecmd_clear_error(); + json_t* discard = NULL; rval = cmd->func(args, output ? output : &discard); json_decref(discard); @@ -575,12 +583,6 @@ void modulecmd_set_error(const char *format, ...) va_end(list); } -static void modulecmd_clear_error() -{ - prepare_error(); - errbuf[0] = '\0'; -} - const char* modulecmd_get_error() { prepare_error(); diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.c index ccbab6ecf..575173e1e 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.c @@ -1679,13 +1679,23 @@ static void callModuleCommand(DCB *dcb, char *domain, char *id, char *v3, { json_t* output = NULL; - if (!modulecmd_call_command(cmd, arg, &output)) + bool succeeded = modulecmd_call_command(cmd, arg, &output); + + if (!succeeded && !output) { - const char* err = modulecmd_get_error(); - dcb_printf(dcb, "Error: %s\n", *err ? err : - "Call to module command failed, see log file for more details"); + const char* s = modulecmd_get_error(); + ss_dassert(s); + + if (*s == 0) + { + // No error had been set, so we add a default one. + modulecmd_set_error("%s", "Call to module command failed, see log file for more details."); + } + + output = modulecmd_get_json_error(); } - else if (output) + + if (output) { char* js = json_dumps(output, JSON_INDENT(4)); dcb_printf(dcb, "%s\n", js);