fix(benchmark-local): handle Ollama connection/response errors gracefully - #705
Open
Anuj04432 wants to merge 2 commits into
Open
fix(benchmark-local): handle Ollama connection/response errors gracefully#705Anuj04432 wants to merge 2 commits into
Anuj04432 wants to merge 2 commits into
Conversation
sanmaxdev
reviewed
Aug 10, 2026
sanmaxdev
left a comment
Contributor
There was a problem hiding this comment.
One error-path issue to address.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
call_ollama()inbenchmarks/benchmark-local.pyhad no error handling around the HTTP request to Ollama or around parsing its response. Any failure there (Ollama not running, wrong model name, unexpected response shape) crashed the whole benchmark run with a raw Python traceback.This PR wraps those two points in try/except and raises a clear
RuntimeErrorinstead:urllib.error.URLError→ Ollama unreachable (not running / wrong URL)json.JSONDecodeError→ Ollama responded with non-JSONKeyError→ response JSON didn't have the expectedmessage.contentshape (e.g. an error payload)Why
This script is meant to be run locally against Ollama (
benchmarks/benchmark-local.py --model llama3.2 --repeat 3), and "Ollama isn't running yet" or "wrong model name" are common, expected mistakes — not exceptional edge cases. Right now those mistakes produce a confusing stack trace instead of telling the user what to check.Before / after
Before (Ollama not reachable):
```
Traceback (most recent call last):
File "benchmark-local.py", line 76, in call_ollama
with urllib.request.urlopen(req, timeout=180) as resp:
...
urllib.error.URLError: <urlopen error [Errno 111] Connection refused>
```
After:
```
RuntimeError: Could not reach Ollama at http://localhost:11434/ (model 'llama3.2'): <urlopen error [Errno 111] Connection refused>. Is Ollama running and is the model pulled?
```
Testing
python -m py_compile benchmarks/benchmark-local.py— passesRuntimeErrorwith a clear message:Scope
Small, self-contained fix — only touches
call_ollama()and one import line. No behavior changes for the success path.