zig
zig copied to clipboard
Comptime error return trace
Zig Version
0.14.0-dev.325+9356cb147
Steps to Reproduce and Observed Output
Given this function:
fn raiseError() !void {
return error.Example;
}
With this comptime call:
pub fn main() void {
comptime raiseError() catch @compileError("example error message");
}
error: example error message
example.zig:6:33: error: example error message
Exit code: -1
With this comptime call:
pub fn main() void {
comptime raiseError() catch unreachable;
}
error: caught unexpected error 'Example'
example.zig:6:30: error: caught unexpected error 'Example'
example.zig:2:15: note: error returned here
Exit code: -1
Currently:
catch @compileErrorreports an error message, but the error return trace is lost.catch unreachabledisplays the error return trace, but doesn't report an error message along.
Arguments against catch unreachable:
- It is meant be discouraged, so it shouldn't be the only way of having a comptime error's trace.
@compileErrorasserts that the value is evaluated at comptime,unreachabledoesn't.
Expected Output
@compileError should display the error return trace when called from an error catching block, the same way unreachable does, along its current behavior.