Skip to content

Commit 84df006

Browse files
stoneclaude
andcommitted
fix: abort with error in batch mode (--exit) when Ollama is unreachable
When Ollama returns a connection error during model info lookup, aider previously treated it as a non-fatal warning and continued with "sane defaults", opening the interactive TUI. In batch mode (--exit), this causes the TUI output to be written to the redirected stdout instead of aborting cleanly. - ModelInfoManager.get_model_info: re-raise exceptions whose message starts with "OllamaError:" instead of silently swallowing them - Model.get_model_info: catch OllamaError, store on self.ollama_error, return {} to allow interactive mode to continue with sane defaults - main.py: if ollama_error is set and --exit is active, emit a clear error message and return 1 Interactive mode is unaffected: the warning and sane-defaults behaviour remain unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bdb4d9f commit 84df006

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

aider/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,13 @@ def get_io(pretty):
887887
analytics.event("exit", reason="Invalid lint command format")
888888
return 1
889889

890+
if main_model.ollama_error and args.exit:
891+
io.tool_error(
892+
f"Cannot connect to Ollama: {main_model.ollama_error}\n"
893+
"Aborting because --exit (batch mode) was specified."
894+
)
895+
return 1
896+
890897
if args.show_model_warnings:
891898
problem = models.sanity_check_models(io, main_model)
892899
if problem:

aider/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ def get_model_info(self, model):
242242
try:
243243
litellm_info = litellm.get_model_info(model)
244244
except Exception as ex:
245+
if str(ex).startswith("OllamaError:"):
246+
raise
245247
if "model_prices_and_context_window.json" not in str(ex):
246248
print(str(ex))
247249

@@ -327,6 +329,7 @@ def __init__(
327329
self.max_chat_history_tokens = 1024
328330
self.weak_model = None
329331
self.editor_model = None
332+
self.ollama_error = None
330333

331334
# Find the extra settings
332335
self.extra_model_settings = next(
@@ -357,7 +360,13 @@ def __init__(
357360
self.get_editor_model(editor_model, editor_edit_format)
358361

359362
def get_model_info(self, model):
360-
return model_info_manager.get_model_info(model)
363+
try:
364+
return model_info_manager.get_model_info(model)
365+
except Exception as ex:
366+
if str(ex).startswith("OllamaError:"):
367+
self.ollama_error = ex
368+
return {}
369+
raise
361370

362371
def _copy_fields(self, source):
363372
"""Helper to copy fields from a ModelSettings instance to self"""

0 commit comments

Comments
 (0)