Handles retry logic with exponential backoff. Args: attempt: Current attempt number retry_delay: Current retry delay in seconds error: The exception that occurred num_retries: Number of retries allowed error_type: Type of
(
self, attempt: int, retry_delay: int, num_retries: int, error: Exception, silent: bool
)
| 45 | payload["render_state"] = run_state.to_dict() |
| 46 | |
| 47 | def _handle_retry_logic( |
| 48 | self, attempt: int, retry_delay: int, num_retries: int, error: Exception, silent: bool |
| 49 | ) -> int: |
| 50 | """ |
| 51 | Handles retry logic with exponential backoff. |
| 52 | |
| 53 | Args: |
| 54 | attempt: Current attempt number |
| 55 | retry_delay: Current retry delay in seconds |
| 56 | error: The exception that occurred |
| 57 | num_retries: Number of retries allowed |
| 58 | error_type: Type of error for logging (e.g., "Network error", "Error") |
| 59 | |
| 60 | Returns: |
| 61 | Updated retry_delay for next attempt |
| 62 | |
| 63 | Raises: |
| 64 | The original exception if max retries exceeded |
| 65 | """ |
| 66 | is_connection_error = isinstance(error, ConnectionError) or isinstance(error, Timeout) |
| 67 | connection_error_type = "Network error" if is_connection_error else "Error" |
| 68 | if attempt < num_retries: |
| 69 | if not silent: |
| 70 | self.console.debug(f"{connection_error_type} on attempt {attempt + 1}/{num_retries + 1}: {error}") |
| 71 | self.console.debug(f"Retrying in {retry_delay} seconds...") |
| 72 | time.sleep(retry_delay) |
| 73 | # Exponential backoff |
| 74 | return retry_delay * 2 |
| 75 | else: |
| 76 | if not silent: |
| 77 | self.console.error(f"Max retries ({num_retries}) exceeded. Last error: {error}") |
| 78 | if is_connection_error: |
| 79 | raise plain2code_exceptions.NetworkConnectionError( |
| 80 | "Connection error: Failed to connect to API server.\n\nPlease check that your internet connection is working." |
| 81 | ) |
| 82 | if isinstance(error, RequestException): |
| 83 | raise Exception(f"Error rendering plain code: {error}\n") from error |
| 84 | raise error |
| 85 | |
| 86 | def _raise_for_error_code(self, response_json): |
| 87 | """Raise appropriate exception based on error code in response.""" |
no test coverage detected