Skip to content

Handle non-Diagnostic entries from Mix compilers - #1281

Merged
lukaszsamson merged 1 commit into
masterfrom
fix-non-struct-compiler-diagnostics
Oct 18, 2026
Merged

lukaszsamson merged 1 commit into
masterfrom
fix-non-struct-compiler-diagnostics

Conversation

@lukaszsamson

Copy link
Copy Markdown
Collaborator

Problem

Third-party Mix compilers can return plain strings (or other terms) in the diagnostics list instead of Mix.Task.Compiler.Diagnostic structs. Mix does not enforce the struct contract, so Build.run_mix_compile/1 passed these straight into Diagnostics.from_mix_task_compiler_diagnostic/3, which only matched the struct. The build process crashed and the user got a generic build error instead of the compiler's message.

Crash report (Elixir 1.20.0):

** (FunctionClauseError) no function clause matching in ElixirLS.LanguageServer.Diagnostics.from_mix_task_compiler_diagnostic/3
  language_server/diagnostics.ex:23: ElixirLS.LanguageServer.Diagnostics.from_mix_task_compiler_diagnostic("Make failed with exit code 2", "/path/mix.exs", "/path")
  Enum.map/2
  language_server/build.ex:200: ElixirLS.LanguageServer.Build.handle_compile_phase/6
  language_server/build.ex:20: anonymous fn/3 in ElixirLS.LanguageServer.Build.build/3

Fix

  • Binary diagnostics become error diagnostics attached to mix.exs (position 0, compiler_name: "Mix"), matching how mixfile-level errors are attached.
  • Any other term is passed through inspect/1 and reported the same way.
  • Struct clause is unchanged.

Tests

Added two cases to apps/language_server/test/diagnostics_test.exs. mix test test/diagnostics_test.exs: 20 passed.

Third-party Mix compilers may return plain strings or other terms in the
diagnostics list instead of Mix.Task.Compiler.Diagnostic structs. This
crashed the build with a FunctionClauseError in
from_mix_task_compiler_diagnostic/3.

Binaries are now reported as error diagnostics attached to mix.exs; other
terms are inspected and reported the same way.
@lukaszsamson
lukaszsamson merged commit 11c3d53 into master Oct 18, 2026
23 checks passed
@lukaszsamson
lukaszsamson deleted the fix-non-struct-compiler-diagnostics branch October 18, 2026 21:56
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

Successfully merging this pull request may close these issues.

1 participant