{"record":{"id":"a5cc3c26c28c679d","repo":"affaan-m/ECC","slug":"ollama-connection-failed-msg","errorCode":null,"errorMessage":"Ollama connection failed: {msg}","messagePattern":"Ollama connection failed: (.+?)","errorType":"exception","errorClass":"AuthenticationError","httpStatus":null,"severity":"error","filePath":"src/llm/providers/ollama.py","lineNumber":104,"sourceCode":"                tool_calls = [\n                    ToolCall(\n                        id=tc.get(\"id\", \"\"),\n                        name=tc.get(\"function\", {}).get(\"name\", \"\"),\n                        arguments=tc.get(\"function\", {}).get(\"arguments\", {}),\n                    )\n                    for tc in result[\"message\"][\"tool_calls\"]\n                ]\n\n            return LLMOutput(\n                content=content,\n                tool_calls=tool_calls,\n                model=model,\n                stop_reason=result.get(\"done_reason\"),\n            )\n        except Exception as e:\n            msg = str(e)\n            if \"401\" in msg or \"connection\" in msg.lower():\n                raise AuthenticationError(f\"Ollama connection failed: {msg}\", provider=ProviderType.OLLAMA) from e\n            if \"429\" in msg or \"rate_limit\" in msg.lower():\n                raise RateLimitError(msg, provider=ProviderType.OLLAMA) from e\n            if \"context\" in msg.lower() and \"length\" in msg.lower():\n                raise ContextLengthError(msg, provider=ProviderType.OLLAMA) from e\n            raise\n\n    def list_models(self) -> list[ModelInfo]:\n        return self._models.copy()\n\n    def validate_config(self) -> bool:\n        return bool(self.base_url)\n\n    def get_default_model(self) -> str:\n        return self.default_model\n","sourceCodeStart":86,"sourceCodeEnd":119,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/src/llm/providers/ollama.py#L86-L119","documentation":"The Ollama provider's generate() maps exceptions with '401' or 'connection' in the message to AuthenticationError with the prefix 'Ollama connection failed:'. It fires when the HTTP client cannot reach the local/remote Ollama server, or the server rejects credentials. Note this conflates network unreachability with authentication, since Ollama usually has no auth.","triggerScenarios":"Calling provider.generate() while the Ollama daemon is not running, the host/port in the base URL is wrong, or the server returns 401; any exception message containing 'connection' triggers it.","commonSituations":"OLLAMA_BASE_URL pointing to the wrong port (11434 is default); Ollama service not started after reboot; Docker container lacking access to host Ollama; reverse proxy requiring auth in front of Ollama.","solutions":["Verify Ollama is running: `ollama list` or `curl http://localhost:11434/api/tags`","Check the configured base URL / port for typos and reachability","If behind a proxy, confirm auth headers or disable the auth requirement","Catch AuthenticationError and surface a 'check Ollama server' message to users"],"exampleFix":"// before\nprovider = OllamaProvider(base_url=\"http://localhost:934\")\n// after\nprovider = OllamaProvider(base_url=\"http://localhost:11434\")","handlingStrategy":"validation","validationCode":"import urllib.request\ntry:\n    urllib.request.urlopen(\"http://localhost:11434/api/tags\", timeout=2)\n    ollama_ready = True\nexcept Exception:\n    ollama_ready = False","typeGuard":null,"tryCatchPattern":"try:\n    resp = provider.generate(inp)\nexcept AuthenticationError as e:\n    raise RuntimeError(\"Cannot reach Ollama — check it is running and the base URL/port\") from e","preventionTips":["Health-check the Ollama endpoint at startup before use","Run Ollama as a supervised service (systemd) so it restarts","Default to http://localhost:11434 and make the port configurable","Distinguish connection vs auth failures in your own wrapper"],"tags":["network","ollama","connection"],"backgroundTag":"connection-refused","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}