ctf: append error causes when returning errors
Change as many error paths as possible in the CTF metadata parsing code
to append error causes. This will give clearer error messages to users
when the metadata can't be parsed. The errors are already printed to
stderr, but this will make them more obvious, as they will be printed in
the error stack.
For example, a syntax error caught by the metadata-info query:
$ cat test/metadata
/* CTF 1.8 */
trace {
foo = ;
};
$ ./src/cli/babeltrace2 query src.ctf.fs metadata-info -p 'path=test'
...
ERROR: [Babeltrace CLI] (/home/simark/src/babeltrace/src/cli/babeltrace2.c:649)
Failed to query component class: unknown error: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=1 object="metadata-info"
CAUSED BY [libbabeltrace2] (/home/simark/src/babeltrace/src/lib/graph/query-executor.c:231)
Component class's "query" method failed: query-exec-addr=0x60b000001430, cc-addr=0x60f000000220, cc-type=SOURCE, cc-name="fs", cc-partial-descr="Read CTF traces from the file sy",
cc-is-frozen=0, cc-so-handle-addr=0x607000000100, cc-so-handle-path="/home/simark/build/babeltrace/src/plugins/ctf/babeltrace-plugin-ctf.la", object="metadata-info", params-addr=0x606000000980,
params-type=MAP, params-element-count=1, log-level=WARNING
CAUSED BY ['source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/fs-src/query.c:121)
Cannot update metadata decoder's content: path="test".
CAUSED BY ['source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/decoder.c:279)
Cannot create the metadata AST out of the metadata text: mdec-addr=0x60c000003a00
CAUSED BY [CTF metadata parser] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/parser.y:925)
At line 4 in metadata stream: syntax error, unexpected CTF_SEMICOLON: token=";"
And a semantic error caught when trying to read the trace:
$ cat test/metadata
/* CTF 1.8 */
trace {
byte_order = 2;
};
$ ./src/cli/babeltrace2 test
...
ERROR: [Babeltrace CLI] (/home/simark/src/babeltrace/src/cli/babeltrace2.c:2462)
Cannot create components.
CAUSED BY [Babeltrace CLI] (/home/simark/src/babeltrace/src/cli/babeltrace2.c:2277)
Cannot create component: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=1, comp-name="auto-disc-source-ctf-fs"
CAUSED BY [libbabeltrace2] (/home/simark/src/babeltrace/src/lib/graph/graph.c:1055)
Component initialization method failed: status=ERROR, comp-addr=0x60c000004f00, comp-name="auto-disc-source-ctf-fs", comp-log-level=WARNING, comp-class-type=SOURCE, comp-class-name="fs", comp-class-partial-descr="Read CTF traces
from the file sy", comp-class-is-frozen=1, comp-class-so-handle-addr=0x607000000100, comp-class-so-handle-path="/home/simark/build/babeltrace/src/plugins/ctf/babeltrace-plugin-ctf.la", comp-input-port-count=0,
comp-output-port-count=0
CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/fs-src/fs.c:1186)
Cannot create trace for `/home/simark/build/babeltrace/test`.
CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/decoder.c:327)
Failed to visit AST node to create CTF IR objects: mdec-addr=0x60c0000052c0, ret=-22
CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.c:4722)
At line 0 in metadata stream: Cannot set trace's native byte order: ret=-22
CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.c:4148)
At line 4 in metadata stream: Invalid `byte_order` attribute in trace (`trace` block): expecting `le`, `be`, or `network`.
CAUSED BY [auto-disc-source-ctf-fs: 'source.ctf.fs'] (/home/simark/src/babeltrace/src/plugins/ctf/common/metadata/visitor-generate-ir.c:920)
At line 4 in metadata stream: "byte_order" attribute: expecting `be`, `le`, `network`, or `native`.
The metadata parser can be used in both component and component class
context. For logging purposes, only a component is passed through
ctf_metadata_decoder_config, when the parsing is done in the context of
a component. To be able to append error causes with the right component
class actor, add the option to pass a component class as well.
Change-Id: I8db734fa27cea5ea3b911e36800d535290c51ad9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5693
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
14 files changed:
This page took 0.026307 seconds and 4 git commands to generate.