Repository navigation
fix: map SFTP permission and v4+ errors to Python exceptions - #104
Merged
Merged
Conversation
wrap_exceptions mapped asyncssh's PermissionDenied, which is the SSH login failure, but not SFTPPermissionDenied, so an SFTP request without permission raised the raw asyncssh exception instead of PermissionError. With sftp_version 4 or later, servers can also report a missing path, an existing file, or the wrong file type with their own codes, which asyncssh raises as SFTPNoSuchPath, SFTPFileAlreadyExists, SFTPNotADirectory and SFTPFileIsADirectory. These now map to FileNotFoundError, FileExistsError, NotADirectoryError and IsADirectoryError. Fixes #102. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the SFTP-to-Python exception mapping changes.
No open issues 🎉
What changed in this PR
This PR updates wrap_exceptions to translate SFTP permission failures and newer protocol error codes into the standard Python exceptions expected by fsspec, addressing issue #102.
Changes:
- Map SFTP permission, missing-path, file-exists, and wrong-file-type errors to Python exceptions with corresponding error numbers.
- Add direct tests for all five mappings and preservation of exception causes.
- Add a permission-denied integration test, skipped when running as root.
| File | Description |
|---|---|
tests/test_utils.py |
Tests the five exception mappings and exception chaining. |
tests/test_sshfs.py |
Tests reading a file with no permissions through the mock server. |
sshfs/utils.py |
Adds SFTP exception handling and corresponding Python error mappings. |
Review effort: Balanced
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.
wrap_exceptionsturns asyncssh errors into the Python exceptions fsspec code expects, but it missed two groups:SFTPPermissionDenied. ThePermissionDeniedit caught is asyncssh's SSH login failure. An SFTP request without permission, such as reading a file with mode000, raised the rawSFTPPermissionDeniedinstead ofPermissionError. This happens with any server, including OpenSSH.sftp_client_kwargs={"sftp_version": 4}or later, servers can report a missing path, an existing file, or the wrong file type with their own codes. asyncssh raises these as separateSFTPErrorsubclasses that weren't caught.SFTPPermissionDeniedPermissionError(EACCES)SFTPNoSuchPath(v4+)FileNotFoundErrorSFTPFileAlreadyExists(v5+)FileExistsErrorSFTPNotADirectory(v6)NotADirectoryErrorSFTPFileIsADirectory(v6)IsADirectoryErrorThe permission fix is outside #102's scope, but it changes the same lines, so a separate PR would conflict with this one.
test_permission_errorreads a file with mode000through the mock server. The mock server only speaks SFTP v3, sotests/test_utils.pychecks each mapping onwrap_exceptionsdirectly. All six tests fail onmain.Fixes #102.
🤖 Generated with Claude Code