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

Incorrect Output for 15-errors-switch.zig on https://ziglang.org/learn/overview/ #425

Open
dmitry-j-mikhin opened this issue Oct 29, 2024 · 0 comments

Comments

@dmitry-j-mikhin
Copy link

dmitry-j-mikhin commented Oct 29, 2024

https://ziglang.org/learn/overview/:
image

Issue Summary

The current test code snippet, when executed using zig build-exe, displays a confusing error message due to a mismatch in usage. This is because zig build-exe expects an entry point with a main function, which is not present in the test file.

Current Output

Using zig build-exe on 15-errors-switch.zig results in the following error, which is uninformative for new users:

$ zig build-exe 15-errors-switch.zig
/home/ci/deps/zig-linux-x86_64-0.13.0/lib/std/start.zig:509:45: error: root struct of file '15-errors-switch' has no member named 'main'
    switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {
                                        ~~~~^~~~~
/home/ci/actions-runner-website/_work/www.ziglang.org/www.ziglang.org/assets/zig-code/features/15-errors-switch.zig:1:1: note: struct declared here
const std = @import("std");
^~~~~
/home/ci/deps/zig-linux-x86_64-0.13.0/lib/std/start.zig:482:20: note: called from here
    return callMain();
           ~~~~~~~~^~
/home/ci/deps/zig-linux-x86_64-0.13.0/lib/std/start.zig:438:36: note: called from here
    std.posix.exit(callMainWithArgs(argc, argv, envp));
                   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
referenced by:
    _start: /home/ci/deps/zig-linux-x86_64-0.13.0/lib/std/start.zig:351:40
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Suggested Solution

Running the file as a test with zig test provides a much clearer, relevant output. This clarifies the specific error being tested in 15-errors-switch.zig and would be more helpful for learners.

Expected Output

Using zig test 15-errors-switch.zig gives meaningful feedback regarding the issue:

$ zig test 15-errors-switch.zig
15-errors-switch.zig:4:40: error: switch must handle all possibilities
    _ = parseInt("hi", 10) catch |err| switch (err) {};
                                       ^~~~~~~~~~~~~~~
test.zig:4:40: note: unhandled error value: 'error.InvalidCharacter'
test.zig:4:40: note: unhandled error value: 'error.DigitExceedsRadix'
test.zig:4:40: note: unhandled error value: 'error.Overflow'

Resolution Suggestion

Update the documentation and code snippets on the overview page to specify using zig test instead of zig build-exe for 15-errors-switch.zig. This will ensure that learners receive relevant error information and improve clarity on Zig's error handling capabilities.

@dmitry-j-mikhin dmitry-j-mikhin changed the title 15-errors-switch.zig test on ziglang.org/learn/overview/ shows wrong output Incorrect Output for 15-errors-switch.zig on https://ziglang.org/learn/overview/ Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant