Decorator that converts tracker exceptions into stderr messages and SystemExit(1).
(fn)
| 44 | |
| 45 | |
| 46 | def handle_errors(fn): |
| 47 | """Decorator that converts tracker exceptions into stderr messages and SystemExit(1).""" |
| 48 | @functools.wraps(fn) |
| 49 | def wrapper(*args, **kwargs): |
| 50 | """Invoke the wrapped command, translating known exceptions to user-facing output.""" |
| 51 | try: |
| 52 | return fn(*args, **kwargs) |
| 53 | except AuthError as e: |
| 54 | err_console.print(f"[bold red]Auth error:[/] {e}") |
| 55 | raise SystemExit(1) |
| 56 | except APIError as e: |
| 57 | err_console.print(f"[bold red]API error {e.status_code}:[/] {e.message}") |
| 58 | raise SystemExit(1) |
| 59 | except httpx.ConnectError: |
| 60 | cfg = load_config() |
| 61 | err_console.print( |
| 62 | f"[bold red]Connection refused.[/] Is InsForge running at {cfg.server_url}?" |
| 63 | ) |
| 64 | raise SystemExit(1) |
| 65 | except httpx.TimeoutException: |
| 66 | err_console.print("[bold red]Request timed out.[/]") |
| 67 | raise SystemExit(1) |
| 68 | except httpx.RequestError as e: |
| 69 | err_console.print(f"[bold red]Network error:[/] {e}") |
| 70 | raise SystemExit(1) |
| 71 | return wrapper |
| 72 | |
| 73 | |
| 74 | def parse_kv_pairs(pairs: tuple[str, ...]) -> dict[str, Any]: |
nothing calls this directly
no outgoing calls
no test coverage detected