Skip to content

fix: handle unreadable config files gracefully at startup - #5609

Open
aniruddhaadak80 wants to merge 1 commit into
Aider-AI:mainfrom
aniruddhaadak80:fix/config-file-open-errors
Open

fix: handle unreadable config files gracefully at startup#5609
aniruddhaadak80 wants to merge 1 commit into
Aider-AI:mainfrom
aniruddhaadak80:fix/config-file-open-errors

Conversation

@aniruddhaadak80

Copy link
Copy Markdown

The problem

Aider crashes with an uncaught traceback at startup when one of its config files exists but cannot be opened:

configargparse opens every file in the default config search path (cwd, git root, home) during parse_known_args(). If a file named .aider.conf.yml exists but is unreadable - permission denied, a broken symlink, or a directory with that name - the raw exception propagates out of aider.main.main() and the user gets a Python traceback instead of a usable message.

The fix

Wrap all three argument-parse calls in main() (parse_known_args twice, then parse_args) with an except OSError handler that:

  • prints Unable to read configuration file: <err> plus a hint to check permissions / that it is a readable file
  • returns exit code 1 instead of dumping a traceback

OSError covers PermissionError, FileNotFoundError, and IsADirectoryError, which are the realistic failure modes here. The existing except AttributeError handling for the boolean-config bug is untouched.

Testing

  • Added tests/basic/test_main.py::TestMain::test_main_with_unreadable_config_file: creates a directory named .aider.conf.yml in cwd (which raises IsADirectoryError on POSIX and PermissionError on Windows when opened), runs main(["--exit"]), and asserts the friendly error is printed and the return code is 1.
  • Full tests/basic/test_main.py suite passes locally (77 passed) on Windows/Python 3.12.
  • pre-commit run --files aider/main.py tests/basic/test_main.py passes (isort, black, flake8, codespell with repo-pinned hook versions).

Fixes #5466
Fixes #4774

configargparse opens each config file while parsing args. If one of the
default config files (e.g. .aider.conf.yml in the repo root) exists but
cannot be opened - permission denied, broken symlink, or a directory
with that name - aider crashed with an uncaught OSError traceback.

Catch OSError from all three parse calls in main(), print a friendly
message naming the file and suggesting a permissions check, and exit
with status 1.

Fixes Aider-AI#5466
Fixes Aider-AI#4774
@CLAassistant

CLAassistant commented Aug 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught PermissionError in configargparse.py line 1216 Soft Linking Configuration - Uncaught OSError in configargparse.py line 1216 -

2 participants