Spaces:
Running
Running
| 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}") | |