Comptime error return trace
Lzard opened this issue · comments
L zard commented
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 @compileError
reports an error message, but the error return trace is lost.catch unreachable
displays 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.
@compileError
asserts that the value is evaluated at comptime,unreachable
doesn'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.