Refactor try_call_all method to return a dictionary of results; update tests for success and partial failures

This commit is contained in:
2025-09-30 12:41:45 +02:00
parent dfe3b4ad90
commit 15182e23c2
2 changed files with 20 additions and 9 deletions

View File

@@ -61,7 +61,7 @@ class WrapperHandler(Generic[W]):
raise Exception(f"All wrappers failed after retries")
def try_call_all(self, func: Callable[[W], T]) -> list[T]:
def try_call_all(self, func: Callable[[W], T]) -> dict[str, T]:
"""
Calls the provided function on all wrappers, collecting results.
If a wrapper fails, it logs a warning and continues with the next.
@@ -73,11 +73,11 @@ class WrapperHandler(Generic[W]):
Raises:
Exception: If all wrappers fail.
"""
results = []
results = {}
for wrapper in self.wrappers:
try:
result = func(wrapper)
results.append(result)
results[wrapper.__class__] = result
except Exception as e:
log_warning(f"{wrapper} failed: {e}")
if not results: