Commit de23ccfad1

Loris Cro <kappaloris@gmail.com>
2025-07-25 17:38:36
build system: print captured stderr on Run step failure
when a Run step that captures stderr fails, no output from it is visible by the user and, since the step failed, any downstream step that would process the captured stream will not run, making it impossible for the user to see the stderr output from the failed process invocation, which makes for a frustrating puzzle when this happens in CI.
1 parent eb1a497
Changed files (1)
lib
std
Build
Step
lib/std/Build/Step/Run.zig
@@ -1391,6 +1391,16 @@ fn runCommand(
             }
         },
         else => {
+            // On failure, print stderr if captured.
+            const bad_exit = switch (result.term) {
+                .Exited => |code| code != 0,
+                .Signal, .Stopped, .Unknown => true,
+            };
+
+            if (bad_exit) if (result.stdio.stderr) |err| {
+                try step.addError("stderr:\n{s}", .{err});
+            };
+
             try step.handleChildProcessTerm(result.term, cwd, final_argv);
         },
     }