summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVitiko <[email protected]>2023-09-14 01:52:45 -0400
committerVitiko <[email protected]>2023-09-14 01:52:45 -0400
commit9cf21242ca30ad2d7642de430d3a17d464ae04e1 (patch)
tree33b39bb7df022534434af925c3e3edf7f4d1413b
parentaf54c65502082ba95268f438262fba44c4bd3f6b (diff)
downloadbazarr-9cf21242ca30ad2d7642de430d3a17d464ae04e1.tar.gz
bazarr-9cf21242ca30ad2d7642de430d3a17d464ae04e1.zip
Add more info to exceptionsv1.2.5-beta.25
-rw-r--r--bazarr/app/get_providers.py33
-rw-r--r--tests/bazarr/test_app_get_providers.py15
2 files changed, 44 insertions, 4 deletions
diff --git a/bazarr/app/get_providers.py b/bazarr/app/get_providers.py
index 98bd1365c..23839046b 100644
--- a/bazarr/app/get_providers.py
+++ b/bazarr/app/get_providers.py
@@ -10,6 +10,8 @@ import pretty
import time
import socket
import requests
+import traceback
+import re
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \
MustGetBlacklisted, SearchLimitReached
@@ -28,6 +30,9 @@ from sonarr.blacklist import blacklist_log
from utilities.analytics import event_tracker
+_TRACEBACK_RE = re.compile(r'File "(.*?)", line (\d+)')
+
+
def time_until_midnight(timezone):
# type: (datetime.datetime) -> datetime.timedelta
"""
@@ -342,15 +347,35 @@ def provider_throttle(name, exception):
tp[name] = (cls_name, throttle_until, throttle_description)
set_throttled_providers(str(tp))
+ trac_info = _get_traceback_info(exception)
+
logging.info("Throttling %s for %s, until %s, because of: %s. Exception info: %r", name,
- throttle_description, throttle_until.strftime("%y/%m/%d %H:%M"), cls_name, exception.args[0]
- if exception.args else None)
- event_tracker.track_throttling(provider=name, exception_name=cls_name, exception_info=exception.args[0]
- if exception.args else None)
+ throttle_description, throttle_until.strftime("%y/%m/%d %H:%M"), cls_name, trac_info)
+ event_tracker.track_throttling(provider=name, exception_name=cls_name, exception_info=trac_info)
update_throttled_provider()
+def _get_traceback_info(exc: Exception):
+ traceback_str = " ".join(traceback.format_tb(exc.__traceback__))
+
+ clean_msg = str(exc).replace("\n", " ").strip()
+
+ line_info = _TRACEBACK_RE.search(traceback_str)
+
+ # Value info char len is 100
+
+ if line_info is None:
+ return clean_msg[:100]
+
+ file_, line = line_info.groups()
+
+ extra = f"' ~ {file_}@{line}"[:90]
+ message = f"'{clean_msg}"[:100 - len(extra)]
+
+ return message + extra
+
+
def throttled_count(name):
global throttle_count
if name in list(throttle_count.keys()):
diff --git a/tests/bazarr/test_app_get_providers.py b/tests/bazarr/test_app_get_providers.py
index e6a31a39f..e8f344ef2 100644
--- a/tests/bazarr/test_app_get_providers.py
+++ b/tests/bazarr/test_app_get_providers.py
@@ -113,3 +113,18 @@ def test_get_language_equals_injected_settings_hi():
result = get_providers.get_language_equals(config)
assert result == [(Language("eng", hi=True), Language("eng"))]
+
+
+def _get_error():
+ try:
+ raise ValueError("Some error" * 100)
+ except ValueError as error:
+ return error
+
+
+def test_get_traceback_info():
+ error_ = _get_error()
+
+ if error_ is not None:
+ msg = get_providers._get_traceback_info(error_)
+ assert len(msg) == 100