Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return full error message from xmllint #586

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions scripts/parse_tools/xml_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ def call_command(commands, logger, silent=False):
False
>>> call_command(['ls'], _LOGGER)
True
>>> try:
... call_command(['ls','--invalid-option'], _LOGGER)
... except CCPPError as e:
... print(str(e))
Execution of 'ls --invalid-option' failed with code: 2
Error output: ls: unrecognized option '--invalid-option'
Try 'ls --help' for more information.
gold2718 marked this conversation as resolved.
Show resolved Hide resolved
>>> try:
... os.chdir(os.path.dirname(__file__))
... call_command(['ls', os.path.basename(__file__), 'foo.bar.baz'], _LOGGER)
... except CCPPError as e:
... print(str(e))
Execution of 'ls xml_tools.py foo.bar.baz' failed with code: 2
xml_tools.py
Error output: ls: cannot access 'foo.bar.baz': No such file or directory
"""
result = False
outstr = ''
Expand All @@ -66,9 +81,17 @@ def call_command(commands, logger, silent=False):
result = False
else:
cmd = ' '.join(commands)
emsg = "Execution of '{}' failed with code:\n"
outstr = emsg.format(cmd, err.returncode)
outstr += "{}".format(err.output)
outstr = f"Execution of '{cmd}' failed with code: {err.returncode}\n"
outstr += f"{err.output.decode('utf-8', errors='replace').strip()}"
if hasattr(err, 'stderr') and err.stderr:
stderr_str = err.stderr.decode('utf-8', errors='replace').strip()
if stderr_str:
if err.output:
outstr += os.linesep
# end if
outstr += f"Error output: {stderr_str}"
gold2718 marked this conversation as resolved.
Show resolved Hide resolved
# end if
# end if
raise CCPPError(outstr) from err
# end if
# end of try
Expand Down
Loading