fix: handle unreadable config files gracefully at startup - #5609
Open
aniruddhaadak80 wants to merge 1 commit into
Open
fix: handle unreadable config files gracefully at startup#5609aniruddhaadak80 wants to merge 1 commit into
aniruddhaadak80 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
Aider crashes with an uncaught traceback at startup when one of its config files exists but cannot be opened:
PermissionError: [Errno 13] Permission denied: 'D:\project\...\.aider.conf.yml'raised fromconfigargparse._open_config_fileswhile parsing argsOSError in configargparse.py line 1216with a symlinked/broken config fileconfigargparseopens every file in the default config search path (cwd, git root, home) duringparse_known_args(). If a file named.aider.conf.ymlexists but is unreadable - permission denied, a broken symlink, or a directory with that name - the raw exception propagates out ofaider.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_argstwice, thenparse_args) with anexcept OSErrorhandler that:Unable to read configuration file: <err>plus a hint to check permissions / that it is a readable file1instead of dumping a tracebackOSErrorcoversPermissionError,FileNotFoundError, andIsADirectoryError, which are the realistic failure modes here. The existingexcept AttributeErrorhandling for the boolean-config bug is untouched.Testing
tests/basic/test_main.py::TestMain::test_main_with_unreadable_config_file: creates a directory named.aider.conf.ymlin cwd (which raisesIsADirectoryErroron POSIX andPermissionErroron Windows when opened), runsmain(["--exit"]), and asserts the friendly error is printed and the return code is1.tests/basic/test_main.pysuite passes locally (77 passed) on Windows/Python 3.12.pre-commit run --files aider/main.py tests/basic/test_main.pypasses (isort, black, flake8, codespell with repo-pinned hook versions).Fixes #5466
Fixes #4774