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.
This commit is contained in:
Loris Cro 2025-07-25 17:38:36 +02:00 committed by Matthew Lugg
parent eb1a4970da
commit de23ccfad1

View file

@ -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);
},
}