Return a short error description if the peer output signals failure, else None.
(output: str, returncode: int)
| 205 | |
| 206 | |
| 207 | def _detect_peer_error(output: str, returncode: int) -> Optional[str]: |
| 208 | """Return a short error description if the peer output signals failure, else None.""" |
| 209 | if returncode not in (0, None): |
| 210 | for kw in _PEER_ERROR_KEYWORDS: |
| 211 | if kw in output: |
| 212 | if "429" in output or "capacity" in output.lower() or "rate" in output.lower(): |
| 213 | return "rate-limited (429) — model capacity exhausted" |
| 214 | return f"exited with code {returncode}" |
| 215 | # Non-zero exit with no known keyword still counts as failure |
| 216 | if returncode != 0: |
| 217 | return f"exited with code {returncode}" |
| 218 | # Check keywords even on exit-0 (some CLIs exit 0 on error) |
| 219 | for kw in _PEER_ERROR_KEYWORDS: |
| 220 | if kw in output: |
| 221 | return "API error in output" |
| 222 | return None |
| 223 | |
| 224 | |
| 225 | def run_prompted(cli_name: str, cmd: str, flag: str, prompt_text: str) -> str: |