Skip to content

fix: map SFTP permission and v4+ errors to Python exceptions - #104

Merged
shcheklein merged 1 commit into
mainfrom
fix/sftp-v4-errors
Nov 29, 2026
Merged

shcheklein merged 1 commit into
mainfrom
fix/sftp-v4-errors

Conversation

@shcheklein

Copy link
Copy Markdown
Collaborator

wrap_exceptions turns asyncssh errors into the Python exceptions fsspec code expects, but it missed two groups:

  • SFTPPermissionDenied. The PermissionDenied it caught is asyncssh's SSH login failure. An SFTP request without permission, such as reading a file with mode 000, raised the raw SFTPPermissionDenied instead of PermissionError. This happens with any server, including OpenSSH.
  • SFTP v4+ codes (SFTP v4+ error codes aren't mapped to Python exceptions #102). With 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 separate SFTPError subclasses that weren't caught.
asyncssh exception Now raises
SFTPPermissionDenied PermissionError (EACCES)
SFTPNoSuchPath (v4+) FileNotFoundError
SFTPFileAlreadyExists (v5+) FileExistsError
SFTPNotADirectory (v6) NotADirectoryError
SFTPFileIsADirectory (v6) IsADirectoryError

The permission fix is outside #102's scope, but it changes the same lines, so a separate PR would conflict with this one.

test_permission_error reads a file with mode 000 through the mock server. The mock server only speaks SFTP v3, so tests/test_utils.py checks each mapping on wrap_exceptions directly. All six tests fail on main.

Fixes #102.

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@shcheklein
shcheklein merged commit 060b82c into main Nov 29, 2026
11 checks passed
@shcheklein
shcheklein deleted the fix/sftp-v4-errors branch November 30, 2026 00:43
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.

SFTP v4+ error codes aren't mapped to Python exceptions

2 participants