✓
Passing This code compiles and runs correctly.
Code
// Pins that a child run with nonzero exit surfaces stderr through the
// | failed arm: the proc returns result.term.Exited as code and a duped copy
// of stderr as msg. (The 2026-07-02 pin was a Term union-tag corruption that
// no longer reproduces; the residual crash was this proc returning a slice
// its own defer freed — a source-level use-after-free, identical in raw Zig.
// msg must be duped because the defers below release Child.run's buffers.)
~import std/io
const std = @import("std");
~tor run-cmd { argv0: string }
| ok i32
| failed { code: i32, msg: string }
~proc run-cmd|zig {
const allocator = std.heap.page_allocator;
const result = std.process.Child.run(.{
.allocator = allocator,
.argv = &[_][]const u8{ argv0, "-c", "printf 'error message to stderr' 1>&2; exit 3" },
}) catch |err| {
return .{ .failed = .{ .code = -1, .msg = @errorName(err) } };
};
defer allocator.free(result.stdout);
defer allocator.free(result.stderr);
if (result.term.Exited != 0) {
const msg = allocator.dupe(u8, result.stderr) catch {
return .{ .failed = .{ .code = @intCast(result.term.Exited), .msg = "stderr dupe failed" } };
};
return .{ .failed = .{ .code = @intCast(result.term.Exited), .msg = msg } };
}
return .{ .ok = 0 };
}
~run-cmd(argv0: "sh")
| ok _ |> std/io:print.ln("ok")
| failed e |> std/io:print.ln(e.msg)
Actual
error message to stderr
Expected output
error message to stderr
Flows
flow ~run-cmd click a branch to expand · @labels scroll to their anchor
run-cmd (argv0: "sh")
Test Configuration
MUST_RUN