Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions aider/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,12 @@ def get_io(pretty):
coder.run(with_message=args.message)
except SwitchCoder:
pass
except ImportError as err:
io.tool_error(str(err))
io.tool_output("Error loading required imports. Did you install aider properly?")
io.offer_url(urls.install_properly, "Open documentation url for more info?")
analytics.event("exit", reason="Message run import error")
return 1
analytics.event("exit", reason="Completed --message")
return

Expand All @@ -1146,6 +1152,12 @@ def get_io(pretty):
io.tool_error(f"Error reading message file: {e}")
analytics.event("exit", reason="Message file IO error")
return 1
except ImportError as err:
io.tool_error(str(err))
io.tool_output("Error loading required imports. Did you install aider properly?")
io.offer_url(urls.install_properly, "Open documentation url for more info?")
analytics.event("exit", reason="Message file import error")
return 1

analytics.event("exit", reason="Completed --message-file")
return
Expand Down Expand Up @@ -1178,6 +1190,12 @@ def get_io(pretty):

if switch.kwargs.get("show_announcements") is not False:
coder.show_announcements()
except ImportError as err:
io.tool_error(str(err))
io.tool_output("Error loading required imports. Did you install aider properly?")
io.offer_url(urls.install_properly, "Open documentation url for more info?")
analytics.event("exit", reason="Main coder.run import error")
return 1


def is_first_run_of_new_version(io, verbose=False):
Expand Down
17 changes: 17 additions & 0 deletions tests/basic/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,23 @@ def test_yes(self, mock_run, MockInputOutput):
args, kwargs = MockInputOutput.call_args
self.assertTrue(args[1])

@patch("aider.main.InputOutput")
@patch("aider.coders.base_coder.Coder.run")
def test_message_import_error_is_reported(self, mock_run, MockInputOutput):
mock_run.side_effect = ImportError("cannot import name 'BaseTransport' from 'httpx'")
mock_io_instance = MockInputOutput.return_value

result = main(["--message", "test message"], input=DummyInput(), output=DummyOutput())

self.assertEqual(result, 1)
mock_io_instance.tool_error.assert_called_with(
"cannot import name 'BaseTransport' from 'httpx'"
)
mock_io_instance.tool_output.assert_any_call(
"Error loading required imports. Did you install aider properly?"
)
mock_io_instance.offer_url.assert_called_once()

@patch("aider.main.InputOutput")
@patch("aider.coders.base_coder.Coder.run")
def test_default_yes(self, mock_run, MockInputOutput):
Expand Down