Blocking sample call with error handling and using custom printer.
(sample: Callable[[], Future],
output: Callable[..., None],
)
| 407 | |
| 408 | |
| 409 | def _sample(sample: Callable[[], Future], |
| 410 | output: Callable[..., None], |
| 411 | ) -> Future: |
| 412 | """Blocking sample call with error handling and using custom printer.""" |
| 413 | |
| 414 | try: |
| 415 | response = sample() |
| 416 | problem_id = response.wait_id() |
| 417 | output("Submitted problem ID: {problem_id}", problem_id=problem_id) |
| 418 | response.result() |
| 419 | except RequestTimeout: |
| 420 | raise CLIError("API connection timed out.", 8) |
| 421 | except PollingTimeout: |
| 422 | raise CLIError("Polling timeout exceeded.", 9) |
| 423 | except InvalidAPIResponseError as e: |
| 424 | raise CLIError(f"Invalid or unexpected API response: {e!s}", 3) |
| 425 | except Exception as e: |
| 426 | raise CLIError(f"Sampling error: {e!s}", 10) |
| 427 | |
| 428 | return response |
| 429 | |
| 430 | |
| 431 | def standardized_output(fn): |