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

ZLS Crashes with panic: reached unreachable code on Windows 11 with VSCode #1442

Closed
TheArchitect4855 opened this issue Sep 14, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@TheArchitect4855
Copy link

Zig Version

0.11.0

Zig Language Server Version

0.11.0

Steps to Reproduce

  1. Install Zig Language extension in VS Code
  2. ZLS will try to start, and crash upon reaching unreachable code

Unfortunately I don't know what specifically is causing this issue, as it seems to happen on any project with any zig code.
I'm happy to give more information/contribute if necessary, I'm just unsure of where to start currently.

Expected Behavior

ZLS does not crash

Actual Behavior

ZLS crashes. Logs:

info : ( main ): Enabled debug logging.

info : ( main ): Starting ZLS 0.11.0 @ 'c:\Users\architect\AppData\Local\zig\zls\bin\zls.exe'
info : ( main ): No config file zls.json found.
info : (config): Using zig executable 'C:\Users\architect\AppData\Local\zig\zig.exe'
info : (config): Using zig lib path 'C:\Users\architect\AppData\Local\zig\lib'
info : (config): Using build runner global cache path 'C:\Users\architect\AppData\Local\zig'
info : (config): Detected runtime zig version: '0.11.0'
info : (server): client is 'Visual Studio Code-1.82.1'
info : (server): zls initializing
info : (server): Server.ClientCapabilities{ .supports_snippets = true, .supports_apply_edits = true, .supports_will_save = true, .supports_will_save_wait_until = true, .supports_publish_diagnostics = true, .supports_code_action_fixall = true, .hover_supports_md = true, .completion_doc_supports_md = true, .label_details_support = true, .supports_configuration = true, .supports_workspace_did_change_configuration_dynamic_registration = true, .supports_textDocument_definition_linkSupport = true }
info : (server): Using offset encoding: utf-16
debug: (server): Took 0ms to process request-0-initialize on Thread 12476
debug: (server): Dynamically registering method 'workspace/didChangeConfiguration'
debug: (server): Took 0ms to process notification-initialized on Thread 12476
debug: (server): Took 2ms to process notification-textDocument/didOpen on Thread 12476
debug: (server): Took 0ms to process response-register-workspace/didChangeConfiguration on Thread 12476
info : (server): Setting configuration...
warning: (server): Ignoring new value for "zls.record_session_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.replay_session_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.builtin_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.zig_lib_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.build_runner_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.global_cache_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.build_runner_global_cache_path": the given new value is invalid
debug: (server): Server.ClientCapabilities{ .supports_snippets = true, .supports_apply_edits = true, .supports_will_save = true, .supports_will_save_wait_until = true, .supports_publish_diagnostics = true, .supports_code_action_fixall = true, .hover_supports_md = true, .completion_doc_supports_md = true, .label_details_support = true, .supports_configuration = true, .supports_workspace_did_change_configuration_dynamic_registration = true, .supports_textDocument_definition_linkSupport = true }
thread 12476 panic: reached unreachable code
???:?:?: 0x7ff702775234 in ??? (zls.exe)
???:?:?: 0x7ff7027365b4 in ??? (zls.exe)
???:?:?: 0x7ff702722096 in ??? (zls.exe)
???:?:?: 0x7ff702720986 in ??? (zls.exe)
???:?:?: 0x7ff7027fb754 in ??? (zls.exe)
???:?:?: 0x7ff7027ba741 in ??? (zls.exe)
???:?:?: 0x7ff70278b1e4 in ??? (zls.exe)
???:?:?: 0x7ff702741141 in ??? (zls.exe)
???:?:?: 0x7ff7027260ee in ??? (zls.exe)
???:?:?: 0x7ff702725a72 in ??? (zls.exe)
???:?:?: 0x7ff7027272ea in ??? (zls.exe)
???:?:?: 0x7ff702727efc in ??? (zls.exe)
???:?:?: 0x7ffe09af257c in ??? (KERNEL32.DLL)
???:?:?: 0x7ffe0ab8aa67 in ??? (ntdll.dll)
[Info  - 9:37:53 AM] Connection to server got closed. Server will restart.

(this happens a few times until VS Code gives up).

@TheArchitect4855 TheArchitect4855 added the bug Something isn't working label Sep 14, 2023
@llogick
Copy link
Contributor

llogick commented Sep 14, 2023

Hi,

First step is to try and reproduce it with a debug build of ZLS (0.11.0 in this case as there have been changes since and it might be fixed in latest).

@TheArchitect4855
Copy link
Author

Logs from running ZLS in debug mode:

info : ( main ): Enabled debug logging.

info : ( main ): Starting ZLS 0.11.0 @ 'C:\Users\thearchitect\Documents\zls\zig-out\bin\zls.exe'
info : ( main ): No config file zls.json found.
info : (config): Using zig executable 'C:\Users\thearchitect\AppData\Local\zig\zig.exe'
info : (config): Using zig lib path 'C:\Users\thearchitect\AppData\Local\zig\lib'
info : (config): Using build runner global cache path 'C:\Users\thearchitect\AppData\Local\zig'
info : (config): Detected runtime zig version: '0.11.0'
info : (server): client is 'Visual Studio Code-1.82.1'
info : (server): zls initializing
info : (server): Server.ClientCapabilities{ .supports_snippets = true, .supports_apply_edits = true, .supports_will_save = true, .supports_will_save_wait_until = true, .supports_publish_diagnostics = true, .supports_code_action_fixall = true, .hover_supports_md = true, .completion_doc_supports_md = true, .label_details_support = true, .supports_configuration = true, .supports_workspace_did_change_configuration_dynamic_registration = true, .supports_textDocument_definition_linkSupport = true }
info : (server): Using offset encoding: utf-16
debug: (server): Took 1ms to process request-0-initialize on Thread 13024
debug: (server): Dynamically registering method 'workspace/didChangeConfiguration'
debug: (server): Took 1ms to process notification-initialized on Thread 13024
debug: (server): Took 1ms to process notification-textDocument/didOpen on Thread 13024
debug: (server): Took 0ms to process response-register-workspace/didChangeConfiguration on Thread 13024
info : (server): Setting configuration...
warning: (server): Ignoring new value for "zls.record_session_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.replay_session_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.builtin_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.zig_lib_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.build_runner_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.global_cache_path": the given new value is invalid
warning: (server): Ignoring new value for "zls.build_runner_global_cache_path": the given new value is invalid
debug: (server): Server.ClientCapabilities{ .supports_snippets = true, .supports_apply_edits = true, .supports_will_save = true, .supports_will_save_wait_until = true, .supports_publish_diagnostics = true, .supports_code_action_fixall = true, .hover_supports_md = true, .completion_doc_supports_md = true, .label_details_support = true, .supports_configuration = true, .supports_workspace_did_change_configuration_dynamic_registration = true, .supports_textDocument_definition_linkSupport = true }
thread 13024 panic: reached unreachable code
C:\Users\thearchitect\AppData\Local\zig\lib\std\os.zig:4603:33: 0x7ff7a09e51c5 in faccessatW (zls.exe.obj)
        .OBJECT_NAME_INVALID => unreachable,
                                ^
C:\Users\thearchitect\AppData\Local\zig\lib\std\fs.zig:2536:29: 0x7ff7a09a6634 in accessW (zls.exe.obj)
        return os.faccessatW(self.fd, sub_path_w, 0, 0);
                            ^
C:\Users\thearchitect\AppData\Local\zig\lib\std\fs.zig:2505:32: 0x7ff7a0992116 in access (zls.exe.obj)
            return self.accessW(sub_path_w.span().ptr, flags);
                               ^
C:\Users\thearchitect\Documents\zls\src\configuration.zig:65:36: 0x7ff7a0990a16 in configChanged (zls.exe.obj)
                std.fs.cwd().access(exe_path, .{}) catch break :not_valid;
                                   ^
C:\Users\thearchitect\Documents\zls\src\Server.zig:734:32: 0x7ff7a0a6b663 in handleConfiguration (zls.exe.obj)
    configuration.configChanged(server.config, &server.runtime_zig_version, server.allocator, null) catch |err| {
                               ^
C:\Users\thearchitect\Documents\zls\src\Server.zig:1849:39: 0x7ff7a0a2a663 in handleResponse (zls.exe.obj)
        try server.handleConfiguration(response.data.result);
                                      ^
C:\Users\thearchitect\Documents\zls\src\Server.zig:1730:58: 0x7ff7a09fb149 in processMessage (zls.exe.obj)
        .response => |response| try server.handleResponse(response),
                                                         ^
C:\Users\thearchitect\Documents\zls\src\Server.zig:1736:33: 0x7ff7a09b1161 in processMessageReportError (zls.exe.obj)
    return server.processMessage(message) catch |err| switch (message) {
                                ^
C:\Users\thearchitect\Documents\zls\src\Server.zig:1760:62: 0x7ff7a099616e in processJob (zls.exe.obj)
            const response = server.processMessageReportError(parsed_message.value) orelse return;
                                                             ^
C:\Users\thearchitect\Documents\zls\src\Server.zig:1583:38: 0x7ff7a0995af2 in loop (zls.exe.obj)
                    server.processJob(job, null);
                                     ^
C:\Users\thearchitect\Documents\zls\src\main.zig:389:20: 0x7ff7a0997361 in main (zls.exe.obj)
    try server.loop();
                   ^
C:\Users\thearchitect\AppData\Local\zig\lib\std\start.zig:339:65: 0x7ff7a0997f7c in WinStartup (zls.exe.obj)
    std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain());
                                                                ^
???:?:?: 0x7ffe09af257c in ??? (KERNEL32.DLL)
???:?:?: 0x7ffe0ab8aa67 in ??? (ntdll.dll)
[Info  - 11:28:41 AM] Connection to server got closed. Server will restart.

As a side note, is ZLS backwards-compatible with zig versions? i.e. if this bug is fixed in master, will that build of ZLS be compatible with Zig 0.11.0?

@llogick
Copy link
Contributor

llogick commented Sep 14, 2023

Check the value of zig exe path in your vscode settings.

@TheArchitect4855
Copy link
Author

C:/Users/thearchitect/AppData/Local/zig/zig.exe, seems OK to me. That's where I have Zig installed.

@llogick
Copy link
Contributor

llogick commented Sep 14, 2023

Yeah, although I'd be suspicious of \ vs / but I'm not running windows to know better.

Can you try resetting the value to default/empty (Gear Icon -> Reset Setting) since it's already in PATH.

@TheArchitect4855
Copy link
Author

TheArchitect4855 commented Sep 14, 2023

Huh, that seems to have worked. Kinda weird, considering Windows is supposed to normalize paths? In any case I guess a decent solution would be to add a check for this scenario and replace / with \.

Thanks a bunch for the help!

@Techatrix
Copy link
Member

does this issue also occur when using ZLS master because this was supposed to be fixed by #1366?

@tuket
Copy link

tuket commented Sep 26, 2023

I had the same issue. In my case it was because I had an extra slash in my path /C:/Users/tuket/Documents/APPS/zig/zig.exe. I don't know how that slash got there!

I got confused because the error message was not helpful. I wish it told me that the path was invalid.

I'm also using 0.11.0. So not sure if it's happening in master or not.

It's a bit inconvenient that ZLS fixes go directly to the master version, while we users use the latest stable release. If you try to use newer version of ZLS with the Zig stable version you get error messages complaining of version mismatch.

@Techatrix
Copy link
Member

This issue has been fixed on master so there is nothing to do.

@Techatrix Techatrix closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants