Skip to content

Commit

Permalink
Return more information on smartctl error. Resolves #23 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngosang authored Jul 27, 2022
1 parent eb26f35 commit 1303201
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions smartprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@

def run(args: List[str]):
"""
runs the smartctl command on the system
Runs the smartctl command on the system
"""
out = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
out = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = out.communicate()

if out.returncode != 0:
if stderr:
print(stderr.decode("utf-8"))
raise Exception('Command returned code {}'.format(out.returncode))
stdout_msg = stdout.decode('utf-8') if stdout is not None else ''
stderr_msg = stderr.decode('utf-8') if stderr is not None else ''
raise Exception(f"Command returned code {out.returncode}. Stdout: '{stdout_msg}' Stderr: '{stderr_msg}'")

return stdout.decode("utf-8")

Expand Down

0 comments on commit 1303201

Please sign in to comment.