From 2b78f65aa9dd970ab481d16e202571c9bec450f3 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 15 May 2019 16:27:26 +0200 Subject: [PATCH 1/1] helper/command: print the command output in case of error In case of error, a command should use command_print() to report the error message, so it get printed only on the session that run the command itself, and the message can be intercepted with the tcl command catch if it has to be handled differently. Current code drops the command output when the command returns error, claiming that it's the command that *should* have printed it already. This is true only if we *abuse* of the LOG functions, but accepting the side issue of having the LOG printed in every session and being unable to catch{} the error message. Since we have switched to command_print(), change the code to propagate the command output also in case of error. Change-Id: I95de424a65e63702bdb3b2277749a0ac6aaaa503 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5178 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/helper/command.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index e8ade3f703..3346a6c379 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -623,15 +623,13 @@ static int run_command(struct command_context *context, } } else if (retval == ERROR_COMMAND_CLOSE_CONNECTION) { /* just fall through for a shutdown request */ - } else if (retval != ERROR_OK) { - /* we do not print out an error message because the command *should* - * have printed out an error - */ - char *full_name = command_name(c, ' '); - LOG_DEBUG("Command '%s' failed with error code %d", - full_name ? full_name : c->name, retval); - free(full_name); } else { + if (retval != ERROR_OK) { + char *full_name = command_name(c, ' '); + LOG_DEBUG("Command '%s' failed with error code %d", + full_name ? full_name : c->name, retval); + free(full_name); + } /* Use the command output as the Tcl result */ Jim_SetResult(context->interp, cmd.output); } -- 2.30.2