Skip to content

Commit

Permalink
async return_cmd should raise on failure
Browse files Browse the repository at this point in the history
Commit 3a9d8ce incorrectly suppresses exceptions when a return_cmd
True RunningCommand is awaited.

Explicitly check for exceptions so they are properly raised.
  • Loading branch information
hartmans committed Jan 9, 2025
1 parent ca44695 commit f4ffeed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ def __await__(self):
async def wait_for_completion():
await self.aio_output_complete.wait()
if self.call_args["return_cmd"]:
# We know the command has completed already,
# but need to catch exceptions
self.wait()
return self
else:
return str(self)
Expand Down
13 changes: 13 additions & 0 deletions tests/sh_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,19 @@ async def main():

asyncio.run(main())

def test_async_return_cmd_exc(self):
py = create_tmp_test(
"""
import sys
sys.exit(1)
"""
)

async def main():
await python(py.name, _async=True, _return_cmd=True)

self.assertRaises(sh.ErrorReturnCode_1, asyncio.run, main())

def test_handle_both_out_and_err(self):
py = create_tmp_test(
"""
Expand Down

0 comments on commit f4ffeed

Please sign in to comment.