Skip to content

Fix BreakpointCondition crash for unregistered breakpoint numbers - #1282

Merged
lukaszsamson merged 1 commit into
masterfrom
fix-breakpoint-condition-missing-number
Oct 18, 2026
Merged

lukaszsamson merged 1 commit into
masterfrom
fix-breakpoint-condition-missing-number

Conversation

@lukaszsamson

Copy link
Copy Markdown
Collaborator

Problem

The debug adapter crashes when the interpreted code calls a breakpoint condition check for a number that is no longer registered:

** (ArgumentError) errors were found at the given arguments:
  * 2nd argument: not a tuple
    :erlang.element(2, nil)
    debug_adapter/breakpoint_condition.ex:146: ElixirLS.DebugAdapter.BreakpointCondition.handle_call/3
    gen_server ...

handle_call({:get_condition, number}, ...) did Enum.find(...) |> elem(1), which fails when no condition with that number exists. This is a race: the instrumented code still calls check_N/1 after the breakpoint was removed or replaced (unregister_condition freed the number), or after clear/0. The GenServer dies and the debuggee's check_N call fails too.

Fix

  • get_condition/2 returns nil for an unregistered number (spec updated).
  • Generated check_N/1 returns false when there is no condition, so the breakpoint does not stop and nothing is logged.

Tests

New tests in apps/debug_adapter/test/breakpoint_condition_test.exs cover get_condition and check_N for never-registered, unregistered, and cleared numbers, and assert the GenServer stays alive.

cd apps/debug_adapter && mix test test/breakpoint_condition_test.exs: 30 tests, 0 failures.

get_condition/2 crashed the GenServer when no condition was registered
under the requested number. The instrumented code can still call
check_N/1 after the breakpoint was removed, replaced, or after clear/0
freed the number, which hit elem(1) on nil.

get_condition/2 now returns nil for an unregistered number, and the
generated check_N/1 functions return false in that case.
@lukaszsamson
lukaszsamson merged commit 45c6fcc into master Oct 18, 2026
23 checks passed
@lukaszsamson
lukaszsamson deleted the fix-breakpoint-condition-missing-number branch October 18, 2026 21:57
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