Skip to content

fix: catch OSError from Path.is_dir() with invalid filenames#5151

Open
12310312long wants to merge 1 commit into
Aider-AI:mainfrom
12310312long:fix/oserror-path-is-dir
Open

fix: catch OSError from Path.is_dir() with invalid filenames#5151
12310312long wants to merge 1 commit into
Aider-AI:mainfrom
12310312long:fix/oserror-path-is-dir

Conversation

@12310312long
Copy link
Copy Markdown

Summary

On macOS/Linux, Path.is_dir() can raise OSError with ENAMETOOLONG (Errno 63) when the path is excessively long or malformed (e.g., when a long --system-prompt value ends up as a positional argument). Three locations in main.py call Path(fname).is_dir() without protection, causing unhandled crashes.

This fix wraps each call site in try/except OSError and provides a user-friendly warning instead of a traceback.

Changes

  • aider/main.py:
    • read_only_fnames loop: wrap .expanduser().resolve() and .is_dir() in try/except, skip invalid paths with a warning
    • Multi-file validation: wrap Path(fname).is_dir() in try/except, treat OSError as an invalid path
    • Single-directory detection: wrap Path(all_files[0]).is_dir() and .resolve() in try/except, error gracefully on failure

Related Issues

Closes #5130 — Uncaught OSError in pathlib.py line 1222
Closes #5082 — Uncaught OSError in pathlib.py line 841

On macOS/Linux, Path.is_dir() can raise OSError (ENAMETOOLONG) when
the path is excessively long or malformed. Wrap calls in try/except
to prevent crashes and provide a user-friendly warning instead.

Closes Aider-AI#5130
Closes Aider-AI#5082

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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 OSError in pathlib.py line 1222 Uncaught OSError in pathlib.py line 841

2 participants