mirror of https://github.com/morpheus65535/bazarr
Add more info to exceptions
This commit is contained in:
parent
af54c65502
commit
9cf21242ca
|
@ -10,6 +10,8 @@ import pretty
|
||||||
import time
|
import time
|
||||||
import socket
|
import socket
|
||||||
import requests
|
import requests
|
||||||
|
import traceback
|
||||||
|
import re
|
||||||
|
|
||||||
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \
|
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \
|
||||||
MustGetBlacklisted, SearchLimitReached
|
MustGetBlacklisted, SearchLimitReached
|
||||||
|
@ -28,6 +30,9 @@ from sonarr.blacklist import blacklist_log
|
||||||
from utilities.analytics import event_tracker
|
from utilities.analytics import event_tracker
|
||||||
|
|
||||||
|
|
||||||
|
_TRACEBACK_RE = re.compile(r'File "(.*?)", line (\d+)')
|
||||||
|
|
||||||
|
|
||||||
def time_until_midnight(timezone):
|
def time_until_midnight(timezone):
|
||||||
# type: (datetime.datetime) -> datetime.timedelta
|
# type: (datetime.datetime) -> datetime.timedelta
|
||||||
"""
|
"""
|
||||||
|
@ -342,15 +347,35 @@ def provider_throttle(name, exception):
|
||||||
tp[name] = (cls_name, throttle_until, throttle_description)
|
tp[name] = (cls_name, throttle_until, throttle_description)
|
||||||
set_throttled_providers(str(tp))
|
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,
|
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]
|
throttle_description, throttle_until.strftime("%y/%m/%d %H:%M"), cls_name, trac_info)
|
||||||
if exception.args else None)
|
event_tracker.track_throttling(provider=name, exception_name=cls_name, exception_info=trac_info)
|
||||||
event_tracker.track_throttling(provider=name, exception_name=cls_name, exception_info=exception.args[0]
|
|
||||||
if exception.args else None)
|
|
||||||
|
|
||||||
update_throttled_provider()
|
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):
|
def throttled_count(name):
|
||||||
global throttle_count
|
global throttle_count
|
||||||
if name in list(throttle_count.keys()):
|
if name in list(throttle_count.keys()):
|
||||||
|
|
|
@ -113,3 +113,18 @@ def test_get_language_equals_injected_settings_hi():
|
||||||
|
|
||||||
result = get_providers.get_language_equals(config)
|
result = get_providers.get_language_equals(config)
|
||||||
assert result == [(Language("eng", hi=True), Language("eng"))]
|
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
|
||||||
|
|
Loading…
Reference in New Issue