Skip to content

Commit

Permalink
Display stderr and stdout when run_command fails
Browse files Browse the repository at this point in the history
Throwing a `CalledProcessError` would hide the
messages when converted into a `Xenapi.Failure`
use a generic `Eception` with a properly formed
detail instead.

Signed-off-by: BenjiReis <[email protected]>
  • Loading branch information
benjamreis committed Sep 19, 2023
1 parent 31357d8 commit 4ef9e5a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SOURCES/etc/xapi.d/plugins/raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def check_raid_pool(session, args):
with OperationLocker():
try:
result = run_command(['mdadm', '--detail', device])
except subprocess.CalledProcessError:
except Exception:
# No RAID
return json.dumps({})

Expand Down
2 changes: 1 addition & 1 deletion SOURCES/etc/xapi.d/plugins/xcpngutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run_command(command, check=True):
stdout, stderr = process.communicate()
code = process.returncode
if check and code != 0:
raise subprocess.CalledProcessError(code, command, None)
raise Exception(f"Command {command} failed with code: {code} and stderr: {stderr}, stdout: {stdout}")
result = {'stdout': stdout, 'stderr': stderr, 'command': command, 'returncode': code}
return result

Expand Down

0 comments on commit 4ef9e5a

Please sign in to comment.