Skip to content

Commit de23ccf

Browse files
kristoff-itmlugg
authored andcommitted
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 commit de23ccf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/std/Build/Step/Run.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,16 @@ fn runCommand(
13911391
}
13921392
},
13931393
else => {
1394+
// On failure, print stderr if captured.
1395+
const bad_exit = switch (result.term) {
1396+
.Exited => |code| code != 0,
1397+
.Signal, .Stopped, .Unknown => true,
1398+
};
1399+
1400+
if (bad_exit) if (result.stdio.stderr) |err| {
1401+
try step.addError("stderr:\n{s}", .{err});
1402+
};
1403+
13941404
try step.handleChildProcessTerm(result.term, cwd, final_argv);
13951405
},
13961406
}

0 commit comments

Comments
 (0)