Skip to content

no error source location when importing non existent source file in zig build project #22930

@Techatrix

Description

@Techatrix

Zig Version

0.14.0-dev.3239+d7b93c787

Steps to Reproduce and Observed Output

  1. initialize a new project with zig init
  2. add const foo = @import("non_existent_file.zig"); to src/main.zig
  3. run zig build

The observed output is the following:

install
└─ install zig-testspace
   └─ zig build-exe zig-testspace Debug native 1 errors
error: unable to load 'src/non_existent_file.zig': FileNotFound
error: the following command failed with 1 compilation errors:
/home/techatrix/.config/Code/User/globalStorage/ziglang.vscode-zig/zig/linux-x86_64-0.14.0-dev.3239+d7b93c787/zig build-exe -ODebug --dep zig-testspace_lib -Mroot=/home/techatrix/zig-testspace/src/main.zig -ODebug -Mzig-testspace_lib=/home/techatrix/zig-testspace/src/root.zig --cache-dir /home/techatrix/zig-testspace/.zig-cache --global-cache-dir /home/techatrix/.cache/zig --name zig-testspace --zig-lib-dir /home/techatrix/.config/Code/User/globalStorage/ziglang.vscode-zig/zig/linux-x86_64-0.14.0-dev.3239+d7b93c787/lib/ --listen=- 
Build Summary: 2/5 steps succeeded; 1 failed
install transitive failure
└─ install zig-testspace transitive failure
   └─ zig build-exe zig-testspace Debug native 1 errors
error: the following build command failed with exit code 1:
/home/techatrix/zig-testspace/.zig-cache/o/0ecb37263bb79ce3abd63cb0ab38457a/build /home/techatrix/.config/Code/User/globalStorage/ziglang.vscode-zig/zig/linux-x86_64-0.14.0-dev.3239+d7b93c787/zig /home/techatrix/.config/Code/User/globalStorage/ziglang.vscode-zig/zig/linux-x86_64-0.14.0-dev.3239+d7b93c787/lib /home/techatrix/zig-testspace /home/techatrix/zig-testspace/.zig-cache /home/techatrix/.cache/zig --seed 0x3c5952fd -Z094682ccc96a6f25

Expected Output

I would expect an error message that is identical to running zig run src/main.zig:

src/main.zig:5:21: error: unable to load 'src/non_existent_file.zig': FileNotFound
const foo = @import("non_existent_file.zig");
                    ^~~~~~~~~~~~~~~~~~~~~~~

I also noticed that zig build --watch -fincremental will report the correct error message but only on the first compile cycle.

The missing source location stops ZLS's build on save feature from providing an error message in this situation. See zigtools/zls#2196.

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions