MCPcopy Create free account
hub / github.com/InsForge/InsForge / handle_errors

Function handle_errors

examples/python-ml-experiment-tracker/tracker/cli.py:46–71  ·  view source on GitHub ↗

Decorator that converts tracker exceptions into stderr messages and SystemExit(1).

(fn)

Source from the content-addressed store, hash-verified

44
45
46def 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
74def parse_kv_pairs(pairs: tuple[str, ...]) -> dict[str, Any]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected