Skip to content

Comments

fix(expert): don't crash on missing root_uri#412

Merged
mhanberg merged 1 commit intoelixir-lang:mainfrom
evnu:fix-397-single_file-crash
Feb 21, 2026
Merged

fix(expert): don't crash on missing root_uri#412
mhanberg merged 1 commit intoelixir-lang:mainfrom
evnu:fix-397-single_file-crash

Conversation

@evnu
Copy link
Contributor

@evnu evnu commented Feb 19, 2026

Opening an .exs file outside of a mix project results in a crash as described in #397. As described in GenLSP.Structures.InitializeParams, the root_uri is allowed to be nil and must be handled accordingly. To avoid crashing on start up in such a case, this PR drops setting the workspace URI in this case. While this doesn't make expert fully functional in single-file mode, with this change allows debugging further problems in the case of root_uri not being set.

Fix #397.

The root_uri is allowed to be nil according to the spec. Fix elixir-lang#397.
@mhanberg
Copy link
Member

@katafrakt can you take a gander at this

@katafrakt
Copy link
Contributor

I tested this, it does not fatally crash, but there's quite a lot of other errors now.

13:37:20.357 [error] ** (FunctionClauseError) no function clause matching in XPExpert.ActiveProjects.active?/1
    (xp_expert 0.1.0-rc.0) lib/expert/active_projects.ex:72: XPExpert.ActiveProjects.active?(nil)
    (xp_expert 0.1.0-rc.0) lib/expert/state.ex:146: XPExpert.State.apply/2
    (xp_expert 0.1.0-rc.0) lib/expert.ex:277: XPExpert.apply_to_state/2
    (xp_expert 0.1.0-rc.0) lib/expert.ex:207: XPExpert.handle_notification/2
    (xp_gen_lsp 0.11.3) lib/gen_lsp.ex:600: anonymous fn/2 in XPGenLSP.handle_notification_sync/3
    (xp_telemetry 1.3.0) /Users/pawel.sw/dev/expert/apps/expert/deps/telemetry/src/telemetry.erl:324: :xp_telemetry.span/3
    (xp_gen_lsp 0.11.3) lib/gen_lsp.ex:599: XPGenLSP.handle_notification_sync/3
    (xp_gen_lsp 0.11.3) lib/gen_lsp.ex:502: XPGenLSP.loop/3

This is likely from new changes in #405 and seem to be caused by completion.

13:37:22.273 [error] ** (FunctionClauseError) no function clause matching in XPExpert.EngineApi.schedule_compile/2
    (xp_expert 0.1.0-rc.0) lib/expert/engine_api.ex:20: XPExpert.EngineApi.schedule_compile(nil, false)
    (xp_expert 0.1.0-rc.0) lib/expert/state.ex:214: XPExpert.State.apply/2
    (xp_expert 0.1.0-rc.0) lib/expert.ex:277: XPExpert.apply_to_state/2
    (xp_expert 0.1.0-rc.0) lib/expert.ex:207: XPExpert.handle_notification/2
    (xp_gen_lsp 0.11.3) lib/gen_lsp.ex:600: anonymous fn/2 in XPGenLSP.handle_notification_sync/3
    (xp_telemetry 1.3.0) /Users/pawel.sw/dev/expert/apps/expert/deps/telemetry/src/telemetry.erl:324: :xp_telemetry.span/3
    (xp_gen_lsp 0.11.3) lib/gen_lsp.ex:599: XPGenLSP.handle_notification_sync/3
    (xp_gen_lsp 0.11.3) lib/gen_lsp.ex:502: XPGenLSP.loop/3

This I think is from formatting request. I haven't seen it earlier, so I'm not sure whats causing it.

Go to definition, references, code actions do not work, but I haven't seen errors related to them.

@katafrakt
Copy link
Contributor

Still an improvement from current main. I think it's worth merging, even if does not solve everything.

Screenshot 2026-02-21 at 13 48 12

This is the error I'm getting on main, but it does not happen on this branch. All the errors I mentioned above are in logs, but are not thrown in the editor.

@mhanberg
Copy link
Member

So it looks like this stop it from crashing, but will still output lots of warning because it's running in an implicitly degraded state.

There will be further work to fulfill #398

@katafrakt
Copy link
Contributor

That's how I understood what we want for 0.1 - not have a visible crash, but getting everything to work is out of this scope and moved to 0.2.

@mhanberg mhanberg merged commit 11ed716 into elixir-lang:main Feb 21, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Crash in XPExpert.State.initialize/2 if root_uri is nil

3 participants