[v6,3/3] dts: store stderr in RemoteCommandExecutionError

Message ID 20240531112042.18736-4-luca.vizzarro@arm.com (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers
Series error and usage improvements |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS

Commit Message

Luca Vizzarro May 31, 2024, 11:20 a.m. UTC
  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

Juraj Linkeš May 31, 2024, 12:51 p.m. UTC | #1
On Fri, May 31, 2024 at 1:22 PM Luca Vizzarro <luca.vizzarro@arm.com> wrote:
>
> 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>

Reviewed-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
  
Jeremy Spewock June 14, 2024, 1:56 p.m. UTC | #2
On Fri, May 31, 2024 at 8:51 AM Juraj Linkeš <juraj.linkes@pantheon.tech> wrote:
>
> On Fri, May 31, 2024 at 1:22 PM Luca Vizzarro <luca.vizzarro@arm.com> wrote:
> >
> > 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>
>
> Reviewed-by: Juraj Linkeš <juraj.linkes@pantheon.tech>

Reviewed-by: Jeremy Spewock <jspewock@iol.unh.edu>
  

Patch

diff --git a/dts/framework/exception.py b/dts/framework/exception.py
index cce1e0231a..8502c41779 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_stderr: str, command_return_code: int):
         """Define the meaning of the first two arguments.
 
         Args:
             command: The executed command.
+            command_stderr: The stderr of the executed command.
             command_return_code: The return code of the executed command.
         """
         self.command = command
+        self._command_stderr = command_stderr
         self._command_return_code = command_return_code
 
     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):
diff --git a/dts/framework/remote_session/remote_session.py b/dts/framework/remote_session/remote_session.py
index ad0f53720a..8db26e9efc 100644
--- a/dts/framework/remote_session/remote_session.py
+++ b/dts/framework/remote_session/remote_session.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
 
 """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.stderr, result.return_code)
         self._logger.debug(f"Received from '{command}':\n{result}")
         self.history.append(result)
         return result