Skip to content

Commit 88c099d

Browse files
committed
fix(tools): allow to save stdout and stderr if the exec command fails
Currently, if a command run by the exec command returns an error code, its stdout and stderr are not saved. It could be beneficial to store at least the stderr if requested. Additionally, avoid creating output files when there is no content and also store the stderr of the failed command to diag.log. Signed-off-by: Frantisek Hrbata <[email protected]>
1 parent e5ee420 commit 88c099d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/idf_py_actions/diag_ext.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
1+
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: Apache-2.0
33
import atexit
44
import difflib
@@ -583,17 +583,18 @@ def cmd_exec(args: Dict, step: Dict, recipe: Dict) -> None:
583583

584584
if p.returncode:
585585
warn(f'Exec command "{cmd}" failed with exit code {p.returncode}')
586-
return
586+
if p.stderr:
587+
dbg(f'stderr: "{p.stderr}"')
587588

588-
if stdout:
589+
if stdout and p.stdout:
589590
try:
590591
stdout_path.parent.mkdir(parents=True, exist_ok=True)
591592
with open(stdout_path, 'a' if append else 'w') as f:
592593
f.write(p.stdout)
593594
except Exception:
594595
warn(f'Cannot write exec command "{cmd}" stdout to "{stdout}"')
595596

596-
if stderr:
597+
if stderr and p.stderr:
597598
try:
598599
stderr_path.parent.mkdir(parents=True, exist_ok=True)
599600
with open(stderr_path, 'a' if append else 'w') as f:

0 commit comments

Comments
 (0)