Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception handling should be added when invoking external commands to handle possible command execution failures or exceptions. #5885

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions avocado/utils/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ def get_disks():
:returns: a list of paths to the physical disks on the system
:rtype: list of str
"""
json_result = process.run("lsblk --json --paths --inverse")
json_data = json.loads(json_result.stdout_text)
try:
json_result = process.run("lsblk --json --paths --inverse")
except process.CmdError as ce:
raise DiskError(f"Error occurred while executing lsblk command: {ce}")
try:
json_data = json.loads(json_result.stdout_text)
except json.JSONDecodeError as je:
raise DiskError(f"Error occurred while parsing JSON data: {je}")
disks = []
for device in json_data["blockdevices"]:
disks.append(device["name"])
Expand Down