Add stderr to an exception object in ShellProcess if return code != 0
Author: davert0Created Jul 17, 2023Updated Sep 27, 2026
Expectation / Proposal
There is currently a difference in behavior between the ShellProcess class and the shell_run_command function.
In the shell_run_command function, if the process ends with a non-zero exit code, it returns the stderr as follows:
msg = (
f"Command failed with exit code {process.returncode}:\n" f"{stderr}"
)On the other hand, the ShellProcess class does not return the stderr:
if self.return_code != 0:
raise RuntimeError(
f"PID {self.pid} failed with return code {self.return_code}."
)I want to implement custom error handling based on the stderr in my custom Prefect task, but it is difficult in the current version because shell_run_command is already decorated as a Prefect task and ShellProcess does not return the stderr.
Traceback / Example
- I would like to help contribute a pull request to resolve this!
Source: PrefectHQ/prefect