Skip to content

launcher.lua: dap.repl left as a truthy error string when nvim-dap isn't installed, would crash on use #332

Closed

Description

@rcasia

Bug

lua/neotest-java/build_tool/launcher.lua resolves an optional dap.repl reference like this:

local _, repl = pcall(require, "dap.repl")
deps.dap_repl = repl

pcall(f, ...) returns (ok, result_or_error). When require("dap.repl") fails (e.g. nvim-dap isn't installed), ok is false and the second return value is the error message string (something like "module 'dap.repl' not found: ..."), not nil. The code discards ok (via _) and unconditionally assigns the second value to repl/deps.dap_repl — so on failure, deps.dap_repl ends up being a truthy string instead of nil.

Impact

Later code in the same file does:

if repl then
    repl.clear()
    -- or
    repl.append(data)
end

Since a plain string is truthy, this branch is taken even when dap.repl failed to load, and repl.clear()/repl.append(...) would then crash with something like attempt to call a string value.

Why this apparently never manifested in production

core/spec_builder/init.lua already asserts require("dap") succeeds before ever reaching launch_debug_test, for the strategy = "dap" code path — so in practice, by the time this code runs, nvim-dap (and therefore dap.repl) is virtually always already present. The bug is real but was effectively unreachable via the plugin's own normal call path. It became directly observable when writing an isolated unit/integration test for launcher.lua (as part of #317's plenary.nvim removal work) with nvim-dap not present in the test's runtime.

Fix

Already fixed in #330 (part of the plenary.nvim removal PR stack):

local ok, repl = pcall(require, "dap.repl")
deps.dap_repl = ok and repl or nil

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions