Skip to content

Commit

Permalink
Merge pull request #93 from AzureAD/raise-without-log
Browse files Browse the repository at this point in the history
Raise without log polluting the console
  • Loading branch information
rayluo committed Jul 22, 2021
2 parents e889c44 + 208e0fc commit a0cfe93
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions msal_extensions/libsecret.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,29 @@
pip install wheel
PYGOBJECT_WITHOUT_PYCAIRO=1 pip install --no-build-isolation pygobject
"""
import logging

logger = logging.getLogger(__name__)

try:
import gi # https://github.com/AzureAD/microsoft-authentication-extensions-for-python/wiki/Encryption-on-Linux # pylint: disable=line-too-long
except ImportError:
logger.exception(
"""Runtime dependency of PyGObject is missing.
raise ImportError("""Unable to import module 'gi'
Runtime dependency of PyGObject is missing.
Depends on your Linux distro, you could install it system-wide by something like:
sudo apt install python3-gi python3-gi-cairo gir1.2-secret-1
If necessary, please refer to PyGObject's doc:
https://pygobject.readthedocs.io/en/latest/getting_started.html
""")
raise
""") # Message via exception rather than log

try:
# pylint: disable=no-name-in-module
gi.require_version("Secret", "1") # Would require a package gir1.2-secret-1
# pylint: disable=wrong-import-position
from gi.repository import Secret # Would require a package gir1.2-secret-1
except (ValueError, ImportError):
logger.exception(
except (ValueError, ImportError) as ex:
raise type(ex)(
"""Require a package "gir1.2-secret-1" which could be installed by:
sudo apt install gir1.2-secret-1
""")
raise
""") # Message via exception rather than log


class LibSecretAgent(object):
"""A loader/saver built on top of low-level libsecret"""
Expand Down Expand Up @@ -134,7 +130,5 @@ def trial_run():
you may need to install gnome-keyring package.
* Headless mode (such as in an ssh session) is not supported.
"""
logger.exception(message) # This log contains trace stack for debugging
logger.warning(message) # This is visible by default
raise
raise RuntimeError(message) # Message via exception rather than log

0 comments on commit a0cfe93

Please sign in to comment.