Spaces:
Running
Running
File size: 830 Bytes
21042c7 9841346 cb1e234 21042c7 cb1e234 9841346 cb1e234 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import logging
from typing import Iterable
logger = logging.getLogger(__name__)
def log_gathered_exceptions(results: list, context: str, queries: Iterable[str]):
"""Log the exceptions in a `return_exceptions=True` gather, named by the
query that produced each.
Takes the queries themselves rather than a SerpQuery: this is the
lowest layer in the codebase and importing the domain model inverted
the dependency for the sake of one attribute access. It also means the
patent and OPS paths can use it.
"""
# strict=False deliberately: this is an error-logging path and must
# never raise on a length mismatch of its own.
for exc, q in zip(results, queries, strict=False):
if isinstance(exc, Exception):
logger.warning(f"Error during {context} for query '{q}': {exc}")
|