I noticed that providing a parameter with a wrong syntax to a query
resulted in no error stack shown by the CLI, even though a bunch of
BT_CLI_LOGE_APPEND_CAUSE are done along the way. We just get the logged
errors:
./src/cli/babeltrace2 query -p 'a=2,' src.ctf.fs yo
11-15 16:17:34.734 6423 6423 E CLI/CFG-CLI-ARGS bt_config_query_from_args@babeltrace2-cfg-cli-args.c:1530 Invalid format for --params option's argument:
Expecting unquoted map key:
a=2,
^
11-15 16:17:34.735 6423 6423 E CLI main@babeltrace2.c:2781 Command-line error: retcode=1
This is because the main function only prints the error stack when the
command execution fails, not when anything earlier fails, like the
creation of the command configuration in this case.
Move the call to print_error_causes at the end, so that the causes are
printed every time we exit with status code 1.
I then found that the amount of vertical blank space in the result was
too damn high:
myprompt$ ./src/cli/babeltrace2 query -p 'a=2,' ctf src.ctf.fs yo
11-15 16:38:15.850 13799 13799 E CLI/CFG-CLI-ARGS bt_config_query_from_args@babeltrace2-cfg-cli-args.c:1530 Invalid format for --params option's argument:
Expecting unquoted map key:
a=2,
^
11-15 16:38:15.851 13799 13799 E CLI main@babeltrace2.c:2781 Command-line error: retcode=1
ERROR: [Babeltrace CLI] (/home/smarchi/src/babeltrace/src/cli/babeltrace2.c:2781)
Command-line error: retcode=1
CAUSED BY [Babeltrace CLI] (/home/smarchi/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c:1530)
Invalid format for --params option's argument:
Expecting unquoted map key:
a=2,
^
myprompt$
So I removed the newlines added by ini_append_error_expecting. I think
it looks readable and more concise this way. Any caller who wants the
newlines can add them itself.
myprompt$ ./src/cli/babeltrace2 query -p 'a=2,' ctf src.ctf.fs yo
11-15 16:41:38.600 15717 15717 E CLI/CFG-CLI-ARGS bt_config_query_from_args@babeltrace2-cfg-cli-args.c:1530 Invalid format for --params option's argument:
Expecting unquoted map key:
a=2,
^
11-15 16:41:38.600 15717 15717 E CLI main@babeltrace2.c:2781 Command-line error: retcode=1
ERROR: [Babeltrace CLI] (/home/smarchi/src/babeltrace/src/cli/babeltrace2.c:2781)
Command-line error: retcode=1
CAUSED BY [Babeltrace CLI] (/home/smarchi/src/babeltrace/src/cli/babeltrace2-cfg-cli-args.c:1530)
Invalid format for --params option's argument:
Expecting unquoted map key:
a=2,
^
myprompt$
Change-Id: Id38159896d595b9c8fcac00b3364577e1ea36883
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2394
Tested-by: jenkins <jenkins@lttng.org>
break;
case BT_CMD_STATUS_ERROR:
retcode = 1;
- print_error_causes();
break;
case BT_CMD_STATUS_INTERRUPTED:
retcode = 2;
}
end:
+ if (retcode == 1) {
+ print_error_causes();
+ }
+
BT_OBJECT_PUT_REF_AND_RESET(cfg);
fini_loaded_plugins();
bt_interrupter_put_ref(the_interrupter);
g_string_append_c(state->ini_error, ' ');
}
- g_string_append_printf(state->ini_error, "^\n\n");
+ g_string_append_c(state->ini_error, '^');
}
static
# shellcheck source=../../utils/utils.sh
SH_TAP=1 source "$UTILSSH"
-NUM_TESTS=11
+NUM_TESTS=15
plan_tests $NUM_TESTS
expect_failure 'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=1' \
'src.query.NonExistentSource' 'the-object' '-p' 'a=2'
+# Wrong parameter syntax.
+expect_failure "Invalid format for --params option's argument:" \
+ 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=3,'
rm -f "$stdout_expected_file"
rm -f "$stdout_file"