diff mbox series

[b4] Report ecode and stderr from check commands

Message ID 20240626-report-check-cmd-stderr-v1-1-50d97e394371@collins.com (mailing list archive)
State Accepted
Headers show
Series [b4] Report ecode and stderr from check commands | expand

Commit Message

Brandon Maier June 26, 2024, 8:37 p.m. UTC
The ecode and stderr from check commands gets silently ignored. This
means if the check failed for some unrelated reason, it will appear as a
success to the patch author.

Treat all output from stderr as failure lines, as it's expected normal
findings would go to stdout.

Treat an error from the ecode as meaningful only if stdout and stderr
were blank, as checkpatch normally returns an ecode error if there are
any findings.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
---
 src/b4/__init__.py | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)


---
base-commit: 131835a44c63511e2def9d7adc680754b7ea502c
change-id: 20240626-report-check-cmd-stderr-84b1cb28aa40

Best regards,

Comments

Konstantin Ryabitsev Sept. 6, 2024, 2:47 p.m. UTC | #1
On Wed, 26 Jun 2024 20:37:50 +0000, Brandon Maier wrote:
> The ecode and stderr from check commands gets silently ignored. This
> means if the check failed for some unrelated reason, it will appear as a
> success to the patch author.
> 
> Treat all output from stderr as failure lines, as it's expected normal
> findings would go to stdout.
> 
> [...]

Applied, thanks!

[1/1] Report ecode and stderr from check commands
      commit: 94adae1b647c048832cb28fc82e71cc21f7433e2

Best regards,
diff mbox series

Patch

diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index 7164d3f..dff7152 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -1520,18 +1520,29 @@  class LoreMessage:
         topdir = git_get_toplevel()
         mycmd = os.path.basename(cmdargs[0])
         ecode, out, err = _run_command(cmdargs, stdin=bdata, rundir=topdir)
+        report = list()
+
         out = out.strip()
         out_lines = out.decode(errors='replace').split('\n') if out else list()
-        report = list()
-        if out_lines:
-            for line in out_lines:
-                flag = 'fail' if 'ERROR:' in line else 'warning'
-                # Remove '-:' from the start of the line, because it's never useful
-                if line.startswith('-:'):
-                    line = line[2:]
-                report.append((flag, f'{mycmd}: {line}'))
-        else:
-            report.append(('success', f'{mycmd}: passed all checks'))
+        for line in out_lines:
+            flag = 'fail' if 'ERROR:' in line else 'warning'
+            # Remove '-:' from the start of the line, because it's never useful
+            if line.startswith('-:'):
+                line = line[2:]
+            report.append((flag, f'{mycmd}: {line}'))
+
+        err = err.strip()
+        err_lines = err.decode(errors='replace').split('\n') if err else list()
+        for line in err_lines:
+            if line.startswith('-:'):
+                line = line[2:]
+            report.append(('fail', f'{mycmd}: {line}'))
+
+        if (not out_lines) and (not err_lines):
+            if ecode:
+                report.append(('fail', f'{mycmd}: Exited with error code {ecode}'))
+            else:
+                report.append(('success', f'{mycmd}: passed all checks'))
 
         save_cache(report, cacheid, suffix='checks', is_json=True)
         return report