Skip to content

Commit 3b9945a

Browse files
author
Zo Bot
committed
narrow status() and benchmark send() exception handlers in cli/main.py
status() makes one httpx.get and one resp.json() call. The narrow set (httpx.RequestError, json.JSONDecodeError) covers everything that can go wrong: RequestError covers connection refused, DNS failure, and timeout (TimeoutException is a RequestError subclass); JSONDecodeError covers a non-JSON response body from the local FreeRelay server. TyperExit is raised after the handler returns, KeyboardInterrupt and SystemExit now propagate to the caller instead of being converted to "FreeRelay not running" message and an exit code 1. The benchmark send() closure only awaits client.post() and inspects the status code. RequestError covers connection refused, timeout, and DNS failure; status codes >= 400 are handled by the existing `if r.status_code == 200` branch and don't raise. The old bare except was also swallowing KeyboardInterrupt during a long benchmark run. Added `import json` at the top so json.JSONDecodeError is reachable without inline-import gymnastics.
1 parent ec9d17f commit 3b9945a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

freerelay/cli/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import annotations
77

88
import asyncio
9+
import json
910
import os
1011
import webbrowser
1112
from pathlib import Path
@@ -185,7 +186,7 @@ def status() -> None:
185186
try:
186187
resp = httpx.get("http://localhost:8000/v1/stats", timeout=5)
187188
data = resp.json()
188-
except Exception:
189+
except (httpx.RequestError, json.JSONDecodeError):
189190
console.print("[red]✗ FreeRelay not running. Start with: freerelay[/red]")
190191
raise typer.Exit(1) from None
191192

@@ -242,7 +243,7 @@ async def send():
242243
)
243244
if r.status_code == 200:
244245
latencies.append((time.time() - start) * 1000)
245-
except Exception:
246+
except httpx.RequestError:
246247
pass
247248

248249
await asyncio.gather(*[send() for _ in range(requests)])

0 commit comments

Comments
 (0)