Skip to content

Commit 1806ec4

Browse files
tbitcsoz-agent
andcommitted
fix: OllamaProvider 404/connection error messages
HTTP 404 -> 'Ollama model not found: qwen2.5:14b - run specsmith ollama pull <model>' OSError/ECONNREFUSED -> 'Ollama not running - start it: ollama serve' Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent 2276572 commit 1806ec4

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/specsmith/agent/providers/ollama.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,29 @@ def stream(
147147
continue
148148

149149
def _post(self, path: str, payload: dict[str, Any]) -> dict[str, Any]:
150+
import urllib.error
151+
150152
req = urllib.request.Request( # noqa: S310
151153
f"{self._base_url}{path}",
152154
data=json.dumps(payload).encode(),
153155
headers={"Content-Type": "application/json"},
154156
)
155-
with urllib.request.urlopen(req, timeout=120) as resp: # noqa: S310
156-
result: dict[str, Any] = json.loads(resp.read())
157-
return result
157+
try:
158+
with urllib.request.urlopen(req, timeout=120) as resp: # noqa: S310
159+
result: dict[str, Any] = json.loads(resp.read())
160+
return result
161+
except urllib.error.HTTPError as e:
162+
if e.code == 404:
163+
raise RuntimeError(
164+
f"Ollama model not found: '{self.model}'\n"
165+
f" Check installed models: specsmith ollama list\n"
166+
f" Download it: specsmith ollama pull {self.model}"
167+
) from e
168+
raise
169+
except OSError as e:
170+
if "Connection refused" in str(e) or "ECONNREFUSED" in str(e):
171+
raise RuntimeError(
172+
f"Ollama not running at {self._base_url}\n"
173+
" Start it: ollama serve (or open the Ollama desktop app)"
174+
) from e
175+
raise

0 commit comments

Comments
 (0)