Skip to content

Commit 37cbdf8

Browse files
committed
Merge remote-tracking branch 'NCAR/develop' into register-phase
2 parents 073ed99 + 49a3c3f commit 37cbdf8

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

scripts/parse_tools/xml_tools.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ def call_command(commands, logger, silent=False):
5151
False
5252
>>> call_command(['ls'], _LOGGER)
5353
True
54+
>>> try:
55+
... call_command(['ls','--invalid-option'], _LOGGER)
56+
... except CCPPError as e:
57+
... print(str(e))
58+
Execution of 'ls --invalid-option' failed with code: 2
59+
Error output: ls: unrecognized option '--invalid-option'
60+
Try 'ls --help' for more information.
61+
>>> try:
62+
... os.chdir(os.path.dirname(__file__))
63+
... call_command(['ls', os.path.basename(__file__), 'foo.bar.baz'], _LOGGER)
64+
... except CCPPError as e:
65+
... print(str(e))
66+
Execution of 'ls xml_tools.py foo.bar.baz' failed with code: 2
67+
xml_tools.py
68+
Error output: ls: cannot access 'foo.bar.baz': No such file or directory
5469
"""
5570
result = False
5671
outstr = ''
@@ -66,9 +81,17 @@ def call_command(commands, logger, silent=False):
6681
result = False
6782
else:
6883
cmd = ' '.join(commands)
69-
emsg = "Execution of '{}' failed with code:\n"
70-
outstr = emsg.format(cmd, err.returncode)
71-
outstr += "{}".format(err.output)
84+
outstr = f"Execution of '{cmd}' failed with code: {err.returncode}\n"
85+
outstr += f"{err.output.decode('utf-8', errors='replace').strip()}"
86+
if hasattr(err, 'stderr') and err.stderr:
87+
stderr_str = err.stderr.decode('utf-8', errors='replace').strip()
88+
if stderr_str:
89+
if err.output:
90+
outstr += os.linesep
91+
# end if
92+
outstr += f"Error output: {stderr_str}"
93+
# end if
94+
# end if
7295
raise CCPPError(outstr) from err
7396
# end if
7497
# end of try

0 commit comments

Comments
 (0)