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: 16 additions & 2 deletions aider/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
if check_config_files_for_yes(default_config_files):
return 1
raise e
except OSError as err:
print(f"Unable to read configuration file: {err}")
print("Check the file's permissions and that it is a readable file, not a directory.")
return 1

if args.verbose:
print("Config files search order, if no --config:")
Expand All @@ -495,13 +499,23 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F

parser = get_parser(default_config_files, git_root)

args, unknown = parser.parse_known_args(argv)
try:
args, unknown = parser.parse_known_args(argv)
except OSError as err:
print(f"Unable to read configuration file: {err}")
print("Check the file's permissions and that it is a readable file, not a directory.")
return 1

# Load the .env file specified in the arguments
loaded_dotenvs = load_dotenv_files(git_root, args.env_file, args.encoding)

# Parse again to include any arguments that might have been defined in .env
args = parser.parse_args(argv)
try:
args = parser.parse_args(argv)
except OSError as err:
print(f"Unable to read configuration file: {err}")
print("Check the file's permissions and that it is a readable file, not a directory.")
return 1

if args.shell_completions:
# Ensure parser.prog is set for shtab, though it should be by default
Expand Down
13 changes: 13 additions & 0 deletions tests/basic/test_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import json
import os
import subprocess
Expand Down Expand Up @@ -100,6 +101,18 @@ def test_main_with_git_config_yml(self):
_, kwargs = MockCoder.call_args
assert kwargs["auto_commits"] is True

def test_main_with_unreadable_config_file(self):
# A directory named .aider.conf.yml can not be opened as a config file.
# aider should print a friendly error and exit non-zero instead of
# dumping an uncaught PermissionError/IsADirectoryError traceback.
# https://github.com/Aider-AI/aider/issues/5466
Path(".aider.conf.yml").mkdir()
stdout = StringIO()
with contextlib.redirect_stdout(stdout):
result = main(["--exit"], input=DummyInput(), output=DummyOutput())
self.assertEqual(result, 1)
self.assertIn("Unable to read configuration file", stdout.getvalue())

def test_main_with_empty_git_dir_new_subdir_file(self):
make_repo()
subdir = Path("subdir")
Expand Down