Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use reference trace to provide better build-on-save source locations for errors #2018

Open
Techatrix opened this issue Aug 31, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Techatrix
Copy link
Member

Example:

const std = @import("std");

pub fn main() !void {
    std.log.info("{}", .{""});
}

Output:

$ zig run foo.zig -freference-trace=12
/nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/fmt.zig:663:17: error: cannot format array without a specifier (i.e. {s} or {any})
                @compileError("cannot format array without a specifier (i.e. {s} or {any})");
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    formatType__anon_9361: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/fmt.zig:627:38
    format__anon_6673: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/fmt.zig:188:23
    print__anon_3923: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/io/Writer.zig:24:26
    defaultLog__anon_2963: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/io.zig:324:47
    log__anon_2562: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/log.zig:125:22
    info__anon_1614: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/log.zig:194:16
    main: foo.zig:4:17
    posixCallMainAndExit: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/start.zig:615:37
    _start: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/start.zig:422:40
    comptime: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/start.zig:92:63
    start: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/std.zig:101:27
    comptime: /nix/store/li7vdsrycv9zgp0phkxgsgn9fayn7cx0-zig-0.14.0-dev.1371+5723fcaac/lib/std/std.zig:160:9

This means that the error is reported in fmt.zig:663:17 instead of foo.zig:4:17. The reference trace could be used to figure out how the error was reached and report it at the callsite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant