fix: error handling
This commit is contained in:
@@ -4,6 +4,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
|
import weakref
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from inspect import getmodule
|
from inspect import getmodule
|
||||||
from typing import Any, Callable
|
from typing import Any, Callable
|
||||||
@@ -12,7 +13,9 @@ from axolotl.telemetry.manager import TelemetryManager
|
|||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
ERROR_HANDLED = False
|
# Use WeakSet to track handled exceptions without preventing garbage collection
|
||||||
|
# This allows deduplication of nested calls while still reporting new errors
|
||||||
|
ERROR_HANDLED: weakref.WeakSet = weakref.WeakSet()
|
||||||
|
|
||||||
|
|
||||||
def sanitize_stack_trace(stack_trace: str) -> str:
|
def sanitize_stack_trace(stack_trace: str) -> str:
|
||||||
@@ -126,11 +129,11 @@ def send_errors(func: Callable) -> Callable:
|
|||||||
try:
|
try:
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
# Only track if we're not already handling an error. This prevents us from
|
# Only track if we haven't already handled this specific exception.
|
||||||
# capturing an error more than once in nested decorated function calls.
|
# This prevents us from capturing the same exception more than once
|
||||||
global ERROR_HANDLED # pylint: disable=global-statement
|
# in nested decorated function calls.
|
||||||
if not ERROR_HANDLED:
|
if exception not in ERROR_HANDLED:
|
||||||
ERROR_HANDLED = True
|
ERROR_HANDLED.add(exception)
|
||||||
|
|
||||||
# Get function module path
|
# Get function module path
|
||||||
module = getmodule(func)
|
module = getmodule(func)
|
||||||
|
|||||||
Reference in New Issue
Block a user