when a invalid format string encountered, the std just gives a tip of the invalid part of that string. nearly impossible to find that format string.
maybe it’s hard to provide the location of the invalid string.
so is it possible to provide, except the invalid part, but also the entire format string too?
In the latest zig source (from git master) and if -freference-trace
flag is used, zig manages to display the correct position (function name, filename, line number and column) of the format string.
Example:
const std = @import("std");
pub fn main() void {
std.debug.print("Hello\n", .{"World"});
}
❯ zig-dev build-exe test.zig -freference-trace
zig/master/lib/std/fmt.zig:206:18: error: unused argument in 'Hello
'
1 => @compileError("unused argument in '" ++ fmt ++ "'"),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
print__anon_3034: zig/master/lib/std/io/Writer.zig:24:26
print__anon_2580: zig/master/lib/std/io.zig:324:47
main: test.zig:4:20
posixCallMainAndExit: zig/master/lib/std/start.zig:605:22
_start: zig/master/lib/std/start.zig:421:40
comptime: zig/master/lib/std/start.zig:92:54
This does not happen using zig 0.13.0, but zig always manages to display the format string.
❯ zig build-exe test.zig
zig/0.13.0/lib/std/fmt.zig:203:18: error: unused argument in 'Hello
'
1 => @compileError("unused argument in '" ++ fmt ++ "'"),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
print__anon_3792: zig/0.13.0/lib/std/io/Writer.zig:24:26
print: zig/0.13.0/lib/std/io.zig:324:47
remaining reference traces hidden; use '-freference-trace' to see all reference traces
3 Likes
Ok.thanks.
1 Like