Avoid crashing if a device disconnects mid-diags

This commit is contained in:
2Shirt 2022-09-24 19:58:41 -07:00
parent 21da84e5e2
commit f008546565
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
4 changed files with 25 additions and 0 deletions

View file

@ -642,6 +642,11 @@ def disk_smart_status_check(dev, mid_run=True) -> None:
color = None
disable_tests = False
# Bail if dev is missing
if not dev.present:
dev.disable_disk_tests()
return
# Check SMART status and attributes
if not hw_smart.smart_status_ok(dev):
msg = 'Critical SMART error detected'

View file

@ -151,12 +151,23 @@ class Disk:
return aligned
@property
def present(self) -> bool:
"""Verify this device is still present, returns bool."""
if not self.path.exists():
self.add_note('Device disconnected', 'RED')
return False
return True
def update_details(self, skip_children=True) -> None:
"""Update disk details using OS specific methods.
Required details default to generic descriptions
and are converted to the correct type.
"""
if not self.present:
return
if PLATFORM == 'Darwin':
self.raw_details = get_disk_details_macos(
self.path, skip_children=skip_children,

View file

@ -380,6 +380,11 @@ def update_smart_details(dev) -> None:
"""Update SMART details via smartctl."""
updated_attributes = {}
# Bail if device was disconnected
if not dev.present:
dev.add_note('Device disconnected', 'RED')
return
# Get SMART data
cmd = [
'sudo',

View file

@ -205,6 +205,10 @@ def mount_volumes(device_path=None, read_write=False, scan_corestorage=False):
cmd.append(device_path)
json_data = get_json_from_command(cmd)
# Bail if json_data is empty
if not json_data:
return
# Build list of volumes
for dev in json_data.get('blockdevices', [{}]):
volumes.extend(_get_volumes(dev))