Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/NCAR/ccpp-framework into…
Browse files Browse the repository at this point in the history
… constituent-tend
  • Loading branch information
peverwhee committed Oct 7, 2024
2 parents d49fcfa + 49a3c3f commit 07e6a1b
Showing 1 changed file with 26 additions and 3 deletions.
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.
>>> 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}"
# end if
# end if
raise CCPPError(outstr) from err
# end if
# end of try
Expand Down

0 comments on commit 07e6a1b

Please sign in to comment.