From 43a2734917731c9976d51236be963159320f0a45 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 28 Apr 2023 08:11:45 -0700 Subject: [PATCH] storage: Handle mount error properly Closes: #2343. - The change is needed due to change in privileged exception handling. Tests: - In vagrant machine, while FreedomBox service is running, run unit tests are root user. Observe that exception is not handled properly without the patch. But a more reasonable error is printed with the patch. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/storage/udisks2.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plinth/modules/storage/udisks2.py b/plinth/modules/storage/udisks2.py index 9b536b40e..5784c0326 100644 --- a/plinth/modules/storage/udisks2.py +++ b/plinth/modules/storage/udisks2.py @@ -196,14 +196,14 @@ def _mount(object_path): try: privileged.mount(block_device.preferred_device, _log_error=False) except Exception as exception: - parts = exception.args[2].split(':') - if parts[1].strip() != 'GDBus.Error': + stderr = exception.args[3].decode() + if 'GDBus.Error' not in stderr: raise - if parts[2].strip() == _ERRORS['AlreadyMounted']: + if _ERRORS['AlreadyMounted'] in stderr: logger.warning('Device is already mounted: %s %s', block_device.id, block_device.preferred_device) - elif parts[2].strip() == _ERRORS['Failed']: + elif _ERRORS['Failed'] in stderr: logger.warning('Mount operation failed: %s %s: %s', block_device.id, block_device.preferred_device, exception)