Skip to content

Commit 54e5ee0

Browse files
committed
dulwich: improve asyncssh vendor errors on auth failure
1 parent 8a86057 commit 54e5ee0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/scmrepo/git/backend/dulwich/asyncssh_vendor.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dulwich.client import SSHVendor
66

77
from scmrepo.asyn import BaseAsyncObject, sync_wrapper
8+
from scmrepo.exceptions import AuthError
89

910
if TYPE_CHECKING:
1011
from asyncssh.connection import SSHClientConnection
@@ -160,17 +161,20 @@ async def _run_command(
160161
MSG_USERAUTH_PK_OK
161162
] = _process_public_key_ok_gh
162163

163-
conn = await asyncssh.connect(
164-
host,
165-
port=port if port is not None else (),
166-
username=username if username is not None else (),
167-
password=password if password is not None else (),
168-
client_keys=[key_filename] if key_filename else (),
169-
ignore_encrypted=not key_filename,
170-
known_hosts=None,
171-
encoding=None,
172-
)
173-
proc = await conn.create_process(command, encoding=None)
164+
try:
165+
conn = await asyncssh.connect(
166+
host,
167+
port=port if port is not None else (),
168+
username=username if username is not None else (),
169+
password=password if password is not None else (),
170+
client_keys=[key_filename] if key_filename else (),
171+
ignore_encrypted=not key_filename,
172+
known_hosts=None,
173+
encoding=None,
174+
)
175+
proc = await conn.create_process(command, encoding=None)
176+
except asyncssh.misc.PermissionDenied as exc:
177+
raise AuthError(f"{username}@{host}:{port or 22}") from exc
174178
return AsyncSSHWrapper(conn, proc)
175179

176180
run_command = sync_wrapper(_run_command)

0 commit comments

Comments
 (0)