storage: Fix regression with showing error messages

In ed09028fcd, when eject was made to run as
superuser inside storage action, parsing of the error messages was not handled
properly. Fix it to show simple error messages about why the eject was not
successful.

Tests performed:

- In a terminal, switch to the directory where a disk is mounted to keep the
mount point busy. Attempt to eject the disk. A large stack trace is shown
without the patch and a clean error message is shown with it.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2020-06-24 07:23:27 -04:00
1 parent 225d86e344
commit 955dfea866
3 files changed
+50 -47

No files matched your search

+6 -2
View File
@@ -259,8 +259,12 @@ def subcommand_mount(arguments):
def subcommand_eject(arguments):
"""Eject a device by its path."""
device_path = arguments.device
drive = eject_drive_of_device(device_path)
print(json.dumps(drive))
try:
drive = eject_drive_of_device(device_path)
print(json.dumps(drive))
except Exception as exception:
print(exception, file=sys.stderr)
sys.exit(1)
def _get_options():