Browse Source

Don't register SentryLogger if sentry_sdk is not available

Jaime van Kessel 5 years ago
parent
commit
116ea76fbb
2 changed files with 11 additions and 1 deletions
  1. 4 1
      plugins/SentryLogger/SentryLogger.py
  2. 7 0
      plugins/SentryLogger/__init__.py

+ 4 - 1
plugins/SentryLogger/SentryLogger.py

@@ -3,7 +3,10 @@
 
 from UM.Logger import LogOutput
 from typing import Set
-from sentry_sdk import add_breadcrumb
+try:
+    from sentry_sdk import add_breadcrumb
+except ModuleNotFoundError:
+    pass
 from typing import Optional
 import os
 

+ 7 - 0
plugins/SentryLogger/__init__.py

@@ -1,6 +1,11 @@
 # Copyright (c) 2019 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 from typing import TYPE_CHECKING, Dict, Any
+try:
+    import sentry_sdk
+    has_sentry = True
+except ModuleNotFoundError:
+    has_sentry = False
 
 from . import SentryLogger
 
@@ -13,4 +18,6 @@ def getMetaData() -> Dict[str, Any]:
 
 
 def register(app: "Application") -> Dict[str, Any]:
+    if not has_sentry:
+        return {}  # Nothing to do here!
     return {"logger": SentryLogger.SentryLogger()}