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

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

Open
Techatrix opened this issue Feb 18, 2025 · 0 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved.

Comments

@Techatrix
Copy link
Contributor

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.

@Techatrix Techatrix added the error message This issue points out an error message that is unhelpful and should be improved. label Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

1 participant