Skip to content

Commit

Permalink
refactor: Better error handling for harden function (grapheneX#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxdv authored Mar 2, 2024
1 parent f9614ef commit ca321b6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions graphenex/core/hrd/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ def run_cmd(self, cmd, shell=True, **kwargs):
"""

cmd = cmd.replace("$USER", os.environ["USER"])
result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=shell, **kwargs)
if result.returncode != 0:
raise PermissionError
try:
result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=shell, **kwargs)
except subprocess.CalledProcessError as e:
raise PermissionError(f"Subprocess err {e} caught while running '{cmd}'")
else:
if result.returncode != 0:
raise PermissionError(f"Command '{cmd}' returned non-zero exit status!")

try:
return result.stdout.decode('utf-8')
Expand Down

0 comments on commit ca321b6

Please sign in to comment.