I’ve been learning zig and I’ve been using print debugging with std.debug.print to inspect and debug my small program.
What I’ve struggled with is understanding and reading compile errors like
install
└─ install c_compiler_in_zig
└─ compile exe c_compiler_in_zig Debug native 2 errors
/home/jr/.local/bin/zig-x86_64-linux-0.16.0/lib/std/Io/Writer.zig:717:13: error: too few arguments
@compileError("too few arguments");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
defaultLogFileTerminal__anon_36438: /home/jr/.local/bin/zig-x86_64-linux-0.16.0/lib/std/log.zig:132:23
defaultLog__anon_36431: /home/jr/.local/bin/zig-x86_64-linux-0.16.0/lib/std/log.zig:108:34
8 reference(s) hidden; use '-freference-trace=10' to see all references
/home/jr/.local/bin/zig-x86_64-linux-0.16.0/lib/std/Io/Writer.zig:1379:21: error: cannot format slice without a specifier (i.e. {s}, {x}, {b64}, or {any})
@compileError("cannot format slice without a specifier (i.e. {s}, {x}, {b64}, or {any})");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: 2 compilation errors
failed command: /home/jr/.local/bin/zig-x86_64-linux-0.16.0/zig build-exe -ODebug -Mroot=/home/jr/dev/zig/c-compiler-in-zig/src/main.zig --cache-dir .zig-cache --global-cache-dir /home/jr/.cache/zig --name c_compiler_in_zig --zig-lib-dir /home/jr/.local/bin/zig-x86_64-linux-0.16.0/lib/ --listen=-
Build Summary: 0/3 steps succeeded (1 failed)
install transitive failure
└─ install c_compiler_in_zig transitive failure
└─ compile exe c_compiler_in_zig Debug native 2 errors
error: the following build command failed with exit code 1:
.zig-cache/o/73d0eff91161ae40a2dfff28e500ee38/build /home/jr/.local/bin/zig-x86_64-linux-0.16.0/zig /home/jr/.local/bin/zig-x86_64-linux-0.16.0/lib /home/jr/dev/zig/c-compiler-in-zig .zig-cache /home/jr/.cache/zig --seed 0xcf7a1437 -Z838168ed0f64d7b2
The first compile error I understood as it has too few arguments, but it would be nice if it referenced the call site where it had too few arguments.
Where my bug was were in these lines of code, where filename were surrounded by braces.
std.log.info(
"usage: c_compiler_in_zig [--lex|--parse|--codegen] {filename} \n",
.{},
);
I’m just wondering if there’s a better way to figure out where these bugs would be given the errors. Would it make sense to show in the stack trace where the error is in the source code?