MCPcopy
hub / github.com/Runnin4ik/dpi-detector / find_cause

Function find_cause

utils/error_classifier.py:14–24  ·  view source on GitHub ↗

Возвращает первое исключение заданного типа из цепочки, или None.

(exc: Exception, target_type: type, max_depth: int = 10)

Source from the content-addressed store, hash-verified

12# ── Утилиты для обхода цепочки исключений ────────────────────────────────────
13
14def find_cause(exc: Exception, target_type: type, max_depth: int = 10) -> Optional[Exception]:
15 """Возвращает первое исключение заданного типа из цепочки, или None."""
16 current = exc
17 for _ in range(max_depth):
18 if isinstance(current, target_type):
19 return current
20 nxt = current.__cause__ or current.__context__
21 if nxt is None:
22 break
23 current = nxt
24 return None
25
26
27def get_errno_from_chain(exc: Exception, max_depth: int = 10) -> Optional[int]:

Callers 2

classify_connect_errorFunction · 0.85
classify_read_errorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected