Skip to content

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

Open
@Techatrix

Description

@Techatrix

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions