From c80e77b0fd4a67b51b9a1b3d7a282ab522df4ddd Mon Sep 17 00:00:00 2001 From: Anuj04432 Date: Sat, 8 Aug 2026 22:18:07 +0530 Subject: [PATCH 1/2] Handle Ollama connection/response errors with clear messages --- benchmarks/benchmark-local.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/benchmarks/benchmark-local.py b/benchmarks/benchmark-local.py index 8ffe58a4..7ef201a2 100644 --- a/benchmarks/benchmark-local.py +++ b/benchmarks/benchmark-local.py @@ -16,8 +16,10 @@ import time import urllib.request import urllib.parse +import urllib.error from pathlib import Path + ROOT = Path(__file__).parent.parent TASKS = [ @@ -73,10 +75,23 @@ def call_ollama(model, system_prompt, user_prompt, ollama_url): method="POST", ) t0 = time.time() - with urllib.request.urlopen(req, timeout=180) as resp: - data = json.loads(resp.read()) + try: + with urllib.request.urlopen(req, timeout=180) as resp: + data = json.loads(resp.read()) + except urllib.error.URLError as e: + raise RuntimeError( + f"Could not reach Ollama at {ollama_url} (model '{model}'): {e}. " + "Is Ollama running and is the model pulled?" + ) from e + except json.JSONDecodeError as e: + raise RuntimeError(f"Ollama returned invalid JSON for model '{model}': {e}") from e elapsed = time.time() - t0 - return data["message"]["content"], round(elapsed, 1) + try: + return data["message"]["content"], round(elapsed, 1) + except KeyError as e: + raise RuntimeError( + f"Unexpected response shape from Ollama for model '{model}': {data}" + ) from e def run(model, repeat, ollama_url): From 658de76027402aa0a8e8a2ca84629d471a90e166 Mon Sep 17 00:00:00 2001 From: Anuj04432 Date: Mon, 10 Aug 2026 19:22:07 +0530 Subject: [PATCH 2/2] Catch HTTPError before URLError to distinguish bad model from connectivity failure --- benchmarks/benchmark-local.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/benchmarks/benchmark-local.py b/benchmarks/benchmark-local.py index 7ef201a2..7aff0577 100644 --- a/benchmarks/benchmark-local.py +++ b/benchmarks/benchmark-local.py @@ -78,6 +78,12 @@ def call_ollama(model, system_prompt, user_prompt, ollama_url): try: with urllib.request.urlopen(req, timeout=180) as resp: data = json.loads(resp.read()) + except urllib.error.HTTPError as e: + body = e.read().decode(errors="replace") + raise RuntimeError( + f"Ollama returned HTTP {e.code} for model '{model}': {body}. " + "Check that the model name is correct and has been pulled." + ) from e except urllib.error.URLError as e: raise RuntimeError( f"Could not reach Ollama at {ollama_url} (model '{model}'): {e}. "