[v5,3/3] dts: store stderr in RemoteCommandExecutionError
Checks
Commit Message
Store the stderr of an executed command in RemoteCommandExecutionError.
Consequently, when the exception is logged the error message includes
the stderr.
Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
---
dts/framework/exception.py | 13 ++++++++++---
dts/framework/remote_session/remote_session.py | 3 ++-
2 files changed, 12 insertions(+), 4 deletions(-)
Comments
> diff --git a/dts/framework/exception.py b/dts/framework/exception.py
> index cce1e0231a..50724acdf2 100644
> --- a/dts/framework/exception.py
> +++ b/dts/framework/exception.py
> @@ -2,6 +2,7 @@
> # Copyright(c) 2010-2014 Intel Corporation
> # Copyright(c) 2022-2023 PANTHEON.tech s.r.o.
> # Copyright(c) 2022-2023 University of New Hampshire
> +# Copyright(c) 2024 Arm Limited
>
> """DTS exceptions.
>
> @@ -129,21 +130,27 @@ class RemoteCommandExecutionError(DTSError):
> severity: ClassVar[ErrorSeverity] = ErrorSeverity.REMOTE_CMD_EXEC_ERR
> #: The executed command.
> command: str
> + _command_stderr: str
> _command_return_code: int
>
> - def __init__(self, command: str, command_return_code: int):
> + def __init__(self, command: str, command_return_code: int, command_stderr: str):
I wanted to change the order here as well to command, command_stderr
and command_return_code last. The API change doesn't matter as DTS is
still experimental
> """Define the meaning of the first two arguments.
>
> Args:
> command: The executed command.
> command_return_code: The return code of the executed command.
> + command_stderr: The stderr of the executed command.
And here.
> """
> self.command = command
> self._command_return_code = command_return_code
> + self._command_stderr = command_stderr
And here.
>
> def __str__(self) -> str:
> - """Include both the command and return code in the string representation."""
> - return f"Command {self.command} returned a non-zero exit code: {self._command_return_code}"
> + """Include the command, its return code and stderr in the string representation."""
> + return (
> + f"Command '{self.command}' returned a non-zero exit code: "
> + f"{self._command_return_code}\nStderr: {self._command_stderr}"
> + )
>
>
> class InteractiveCommandExecutionError(DTSError):
On 30/05/2024 16:47, Juraj Linkeš wrote:
>> @@ -129,21 +130,27 @@ class RemoteCommandExecutionError(DTSError):
>> severity: ClassVar[ErrorSeverity] = ErrorSeverity.REMOTE_CMD_EXEC_ERR
>> #: The executed command.
>> command: str
>> + _command_stderr: str
>> _command_return_code: int
>>
>> - def __init__(self, command: str, command_return_code: int):
>> + def __init__(self, command: str, command_return_code: int, command_stderr: str):
>
> I wanted to change the order here as well to command, command_stderr
> and command_return_code last. The API change doesn't matter as DTS is
> still experimental
>
Ack.
>> """Define the meaning of the first two arguments.
>>
>> Args:
>> command: The executed command.
>> command_return_code: The return code of the executed command.
>> + command_stderr: The stderr of the executed command.
>
> And here.
>
Ack.
>> """
>> self.command = command
>> self._command_return_code = command_return_code
>> + self._command_stderr = command_stderr
>
> And here.
>
Ack.
@@ -2,6 +2,7 @@
# Copyright(c) 2010-2014 Intel Corporation
# Copyright(c) 2022-2023 PANTHEON.tech s.r.o.
# Copyright(c) 2022-2023 University of New Hampshire
+# Copyright(c) 2024 Arm Limited
"""DTS exceptions.
@@ -129,21 +130,27 @@ class RemoteCommandExecutionError(DTSError):
severity: ClassVar[ErrorSeverity] = ErrorSeverity.REMOTE_CMD_EXEC_ERR
#: The executed command.
command: str
+ _command_stderr: str
_command_return_code: int
- def __init__(self, command: str, command_return_code: int):
+ def __init__(self, command: str, command_return_code: int, command_stderr: str):
"""Define the meaning of the first two arguments.
Args:
command: The executed command.
command_return_code: The return code of the executed command.
+ command_stderr: The stderr of the executed command.
"""
self.command = command
self._command_return_code = command_return_code
+ self._command_stderr = command_stderr
def __str__(self) -> str:
- """Include both the command and return code in the string representation."""
- return f"Command {self.command} returned a non-zero exit code: {self._command_return_code}"
+ """Include the command, its return code and stderr in the string representation."""
+ return (
+ f"Command '{self.command}' returned a non-zero exit code: "
+ f"{self._command_return_code}\nStderr: {self._command_stderr}"
+ )
class InteractiveCommandExecutionError(DTSError):
@@ -2,6 +2,7 @@
# Copyright(c) 2010-2014 Intel Corporation
# Copyright(c) 2022-2023 PANTHEON.tech s.r.o.
# Copyright(c) 2022-2023 University of New Hampshire
+# Copyright(c) 2024 Arm Limited
"""Base remote session.
@@ -172,7 +173,7 @@ def send_command(
)
self._logger.debug(f"stdout: '{result.stdout}'")
self._logger.debug(f"stderr: '{result.stderr}'")
- raise RemoteCommandExecutionError(command, result.return_code)
+ raise RemoteCommandExecutionError(command, result.return_code, result.stderr)
self._logger.debug(f"Received from '{command}':\n{result}")
self.history.append(result)
return result