Skip to content

Commit 6a5bba0

Browse files
committed
Ensure response handler are called with response=nil if there is an error
Alternative to #1469 The `response.body` was reused as `response` despite having an error set based on `success=false`
1 parent a720d49 commit 6a5bba0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lua/dap/session.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ function Session:handle_body(body)
10901090
vim.schedule(function()
10911091
local before = listeners.before[decoded.command]
10921092
call_listener(before, self, err, response, request, decoded.request_seq)
1093-
callback(err, decoded.body, decoded.request_seq)
1093+
callback(err, response, decoded.request_seq)
10941094
local after = listeners.after[decoded.command]
10951095
call_listener(after, self, err, response, request, decoded.request_seq)
10961096
end)

spec/integration_spec.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ describe('dap with fake server', function()
2424
require('dap.breakpoints').clear()
2525
wait(function() return dap.session() == nil end)
2626
end)
27+
28+
it("handler is called without response if there is an error", function()
29+
local session = run_and_wait_until_initialized(config, server)
30+
server.client.threads = function(self, request)
31+
self:send_err_response(request, "this is wrong", "err1")
32+
end
33+
34+
local err, resp
35+
session:request("threads", nil, function (e, r)
36+
err = e
37+
resp = r
38+
end)
39+
wait(function() return err ~= nil end)
40+
assert.is_nil(resp)
41+
assert.are.same(tostring(err), "this is wrong")
42+
end)
43+
2744
it('clear breakpoints clears all active breakpoints', function()
2845
local session = run_and_wait_until_initialized(config, server)
2946
assert.are_not.same(session, nil)

0 commit comments

Comments
 (0)