Skip to content

Commit 130cc39

Browse files
handle StopIteration properly
This commit addresses the bug described in: <datalad#596 (comment)>. The reason for the `AttributeError` was that un-caught `StopIteration` exceptions prevented an initialization of the `returncode`-attribute. This is fixed by initializing the attribute in the constructor of `ShellCommandResponseGenerator`. The commit adds a regression test that ensures that the correct error is signaled.
1 parent eff24d2 commit 130cc39

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

datalad_next/utils/shell_connection.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def train(queue: Queue):
7474
if result_0.returncode != 1:
7575
raise RuntimeError(
7676
'unexpected return code from command'
77-
f'`test`: {result_0.returncode}')
77+
f'`test`: {result_0.returncode}, '
78+
f'stderr: {b"".join(result_0.stderr_deque)}')
7879

7980
# Return the now ready connection
8081
yield cmd_executor
@@ -271,7 +272,7 @@ def __init__(self,
271272
self.end_marker = end_marker
272273
self.state = 'output'
273274
self.returncode_chunk = b''
274-
self.returncode: int
275+
self.returncode: int | None = None
275276

276277
def send(self, _):
277278
if self.state == 'output':

datalad_next/utils/tests/test_shell_connection.py

+7
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,10 @@ def test_delete(sshserver):
222222
# verify that the remote files were deleted
223223
for file in files_to_delete:
224224
assert not (local_path / file).exists()
225+
226+
227+
def test_returncode():
228+
with pytest.raises(RuntimeError) as e:
229+
with shell_connection(['ssh', 'xyz@localhost:22']) as ssh:
230+
pass
231+
print(repr(e))

0 commit comments

Comments
 (0)