Skip to content

Raise without log polluting the console #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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