Better keyring error handling

This commit is contained in:
karimpwnz 2021-01-02 17:44:16 +02:00
parent 4b973fe95d
commit 3b9d4f0b0c

View file

@ -176,7 +176,9 @@ def get_keychain(journal_name):
try: try:
return keyring.get_password("jrnl", journal_name) return keyring.get_password("jrnl", journal_name)
except (keyring.errors.KeyringError, RuntimeError): except keyring.errors.KeyringError as e:
if not isinstance(e, keyring.errors.NoKeyringError):
print("Failed to retrieve keyring", file=sys.stderr)
return "" return ""
@ -191,10 +193,11 @@ def set_keychain(journal_name, password):
else: else:
try: try:
keyring.set_password("jrnl", journal_name, password) keyring.set_password("jrnl", journal_name, password)
except (keyring.errors.KeyringError): except keyring.errors.KeyringError as e:
pass if isinstance(e, keyring.errors.NoKeyringError):
except (keyring.errors.NoKeyringError):
print( print(
"Keyring backend not found. Please install one of the supported backends by visiting: https://pypi.org/project/keyring/", "Keyring backend not found. Please install one of the supported backends by visiting: https://pypi.org/project/keyring/",
file=sys.stderr, file=sys.stderr,
) )
else:
print("Failed to retrieve keyring", file=sys.stderr)