From 9fd0ac333e236b5d26a0cd3b79a445ae740df57f Mon Sep 17 00:00:00 2001 From: Konstantinos Karmas Date: Mon, 21 Jun 2021 16:47:47 +0200 Subject: [PATCH] Don't check against generic exception Define the KeychainDenied exception locally in non-Mac operating systems. CURA-8332 --- cura/OAuth2/KeyringAttribute.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cura/OAuth2/KeyringAttribute.py b/cura/OAuth2/KeyringAttribute.py index 4821f94505..817bf9396d 100644 --- a/cura/OAuth2/KeyringAttribute.py +++ b/cura/OAuth2/KeyringAttribute.py @@ -4,7 +4,7 @@ from typing import Type, TYPE_CHECKING, Optional, List import keyring from keyring.backend import KeyringBackend -from keyring.errors import NoKeyringError, PasswordSetError +from keyring.errors import NoKeyringError, PasswordSetError, KeyringError from UM.Logger import Logger @@ -22,6 +22,9 @@ if Platform.isOSX() and hasattr(sys, "frozen"): from keyring.backends.macOS import Keyring from keyring.backends.macOS.api import KeychainDenied keyring.set_keyring(Keyring()) +else: + class KeychainDenied(Exception): + pass # Even if errors happen, we don't want this stored locally: DONT_EVER_STORE_LOCALLY: List[str] = ["refresh_token"] @@ -40,12 +43,9 @@ class KeyringAttribute: self._store_secure = False Logger.logException("w", "No keyring backend present") return getattr(instance, self._name) - except Exception as e: + except KeychainDenied: self._store_secure = False - if Platform.isOSX() and hasattr(sys, "frozen") and type(e) == KeychainDenied: - Logger.log("i", "Access to the keyring was denied.") - else: - Logger.logException("w", f"Something went wrong while trying to retrieve the password from the Keyring. Exception: {e}") + Logger.log("i", "Access to the keyring was denied.") return getattr(instance, self._name) else: return getattr(instance, self._name)