[Concept,01/24] u_boot_pylib: command: Convert output before raising exception

Message ID 20260103011908.149445-2-sjg@u-boot.org
State New
Headers
Series Malloc debugging and test/py improvements |

Commit Message

Simon Glass Jan. 3, 2026, 1:18 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Call to_output() before raising CommandExc so that callers catching
the exception get string output rather than bytes. This avoids the need
for callers to handle bytes decoding themselves.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 tools/u_boot_pylib/command.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/tools/u_boot_pylib/command.py b/tools/u_boot_pylib/command.py
index cb7ebf49ce5..6b3f9fe59bf 100644
--- a/tools/u_boot_pylib/command.py
+++ b/tools/u_boot_pylib/command.py
@@ -136,9 +136,10 @@  def run_pipe(pipe_list, infile=None, outfile=None, capture=False,
         if result.stdout and oneline:
             result.output = result.stdout.rstrip(b'\r\n')
     result.return_code = last_pipe.wait()
+    result = result.to_output(binary)
     if raise_on_error and result.return_code:
         raise CommandExc(f"Error running '{user_pipestr}'", result)
-    return result.to_output(binary)
+    return result
 
 
 def output(*cmd, **kwargs):