Skip to content

Commit

Permalink
enh: properly catch CalledProcessError in run_command
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Oct 18, 2024
1 parent df50620 commit b1599a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.62.2
- enh: properly catch CalledProcessError in run_command
- ref: replace sp.check_output with run_command in lme4 submodule
0.62.1
- fix: numpy-version-specific default for `copy` in `__array__()`
Expand Down
12 changes: 11 additions & 1 deletion dclab/lme4/rsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
_has_r = None


class CommandFailedError(BaseException):
"""Used when `run_command` encounters an error"""
pass


class RNotFoundError(BaseException):
pass

Expand Down Expand Up @@ -160,7 +165,12 @@ def run_command(cmd, **kwargs):
# Convert paths to strings
cmd = [str(cc) for cc in cmd]

tmp = sp.check_output(cmd, **kwargs)
try:
tmp = sp.check_output(cmd, **kwargs)
except sp.CalledProcessError as e:
raise CommandFailedError(f"The command '{' '.join(cmd)}' failed with "
f"exit code {e.returncode}: {e.output}")

return tmp.strip()


Expand Down

0 comments on commit b1599a2

Please sign in to comment.