Open RossComputerGuy opened 1 year ago
Same issue with 0.11.0-dev.2154+2089b3f19.
Wow, this issue is fixed in https://github.com/ziglang/zig/commit/49d37e2d179948f526f500043c6ea9ae324e9476.
@RossComputerGuy Would you mind give another try?
That's unrelated to this issue and I've tried several times to rebuild but I get the same issue.
Could you provide a minimal example to reproduce this issue?
This should work and should print out only a FileNotFound
error with no trace.
const std = @import("std");
fn make_step(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
_ = step;
_ = prog_node;
return error.FileNotFound;
}
pub fn build(b: *std.Build) void {
var step = std.Build.Step.init(.{
.id = .custom,
.name = "Failure",
.owner = b,
.makeFn = make_step,
});
b.default_step.dependOn(&step);
}
I try your build.zig
, but got segfault in my macbook...
$ zig build
Segmentation fault at address 0x0
/Users/jiacai/x/zig-macos-aarch64-0.11.0-dev.2168+322ace70f/lib/std/mem.zig:199:31: 0x100641524 in copy__anon_6567 (build)
for (dest[0..source.len], source) |*d, s|
^
/Users/jiacai/x/zig-macos-aarch64-0.11.0-dev.2168+322ace70f/lib/std/array_list.zig:886:45: 0x1006d255b in ensureTotalCapacityPrecise (build)
mem.copy(T, new_memory, self.items);
^
/Users/jiacai/x/zig-macos-aarch64-0.11.0-dev.2168+322ace70f/lib/std/array_list.zig:861:51: 0x1006ad27f in ensureTotalCapacity (build)
return self.ensureTotalCapacityPrecise(allocator, better_capacity);
^
/Users/jiacai/x/zig-macos-aarch64-0.11.0-dev.2168+322ace70f/lib/std/array_list.zig:914:41: 0x100668d57 in addOne (build)
try self.ensureTotalCapacity(allocator, newlen);
0.11.0-dev.2168+322ace70f
Yeah, I have the same segfault. Code wise, it should work but it doesn't.
@jiacai2050 I decided to take a look at why the example wouldn't work and I just had to allocate step:
const std = @import("std");
fn make_step(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
_ = step;
_ = prog_node;
return error.FileNotFound;
}
pub fn build(b: *std.Build) !void {
var step = try b.allocator.create(std.Build.Step);
step.* = std.Build.Step.init(.{
.id = .custom,
.name = "Failure",
.owner = b,
.makeFn = make_step,
});
b.default_step.dependOn(step);
}
Log:
Failure: error: FileNotFound
Build Summary: 0/2 steps succeeded; 1 failed (disable with -fno-summary)
install transitive failure
└─ Failure failure
And it happens as expected of the issue, it prints error: FileNotFound
but it's hard to debug because no trace is printed.
This is not confirmed to be a bug yet. Can I see your custom build step logic? Also could you perhaps not use a custom step?
I saw this originally here but I don't have an exact point of failure due to the stack trace not being printed. Also, what would be the alternative to a custom step if a custom step isn't supposed to be used?
Whatever needs being done, it can be done by one of these:
If all else fails, a RunStep allows for arbitrary code execution - and such code will be done in a sub-process, so you have no chance of accidentally misusing the build system custom step API.
It looks like std
defined steps print a stack trace on error but custom steps do not.
ls: unrecognized option '--broken-arg'
詳しくは 'ls --help' を実行して下さい。
The following command exited with code 2 (expected exited with code 0):
cd /home/ross/ExpidusOS && ls --broken-arg
error: UnexpectedExit
/nix/store/innnzvrqknfq288r5knzpfl618da8hma-zig-0.11.0-dev.1910+6d7fb8f19/lib/std/Build/RunStep.zig:424:9: 0x2c8670 in runCommand (build)
return error.UnexpectedExit;
^
/nix/store/innnzvrqknfq288r5knzpfl618da8hma-zig-0.11.0-dev.1910+6d7fb8f19/lib/std/Build/RunStep.zig:290:5: 0x2b0dd9 in make (build)
try runCommand(
^
/nix/store/innnzvrqknfq288r5knzpfl618da8hma-zig-0.11.0-dev.1910+6d7fb8f19/lib/std/Build/Step.zig:75:5: 0x26e3cb in make (build)
try self.makeFn(self);
^
/nix/store/innnzvrqknfq288r5knzpfl618da8hma-zig-0.11.0-dev.1910+6d7fb8f19/lib/std/Build.zig:760:5: 0x25a6fa in makeOneStep (build)
try s.make();
^
/nix/store/innnzvrqknfq288r5knzpfl618da8hma-zig-0.11.0-dev.1910+6d7fb8f19/lib/std/Build.zig:754:13: 0x25a69d in makeOneStep (build)
return err;
^
/nix/store/innnzvrqknfq288r5knzpfl618da8hma-zig-0.11.0-dev.1910+6d7fb8f19/lib/std/Build.zig:715:9: 0x25a441 in make (build)
try self.makeOneStep(s);
^
/nix/store/innnzvrqknfq288r5knzpfl618da8hma-zig-0.11.0-dev.1910+6d7fb8f19/lib/build_runner.zig:259:21: 0x25da12 in main (build)
else => return err,
const std = @import("std");
const Build = std.Build;
pub fn build(b: *Build) !void {
const exec = b.addSystemCommand(&.{
"ls",
"--broken-arg",
});
b.default_step.dependOn(&exec.step);
}
Not sure why custom steps don't print error traces. It really should be printed because there's cases where just from error names, not enough information is provided. There's always a proposal like #2647 but imo, it probably would be best to have at the very least error traces printed when a function fails in zig build
.
Zig Version
0.11.0-dev.2160+49d37e2d1
Steps to Reproduce and Observed Behavior
With the introduction of #14647, I've noticed that custom steps made in
build.zig
will no longer show an error trace. Because of this, it is difficult to debug certain issues even with-freference-trace
set.Example:
As you can see, an error occurred in a step called "Scan Protocols" but it is difficult to understand where the error is coming from.
Expected Behavior
Either
-freference-trace
should at least be able to show the trace or when an error is thrown in a custom step, the trace is shown automatically.