Skip to content

Commit 764899d

Browse files
committed
Fix nil body handling in fmt_error
1 parent 3c3e0a8 commit 764899d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lua/dap/utils.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local M = {}
44
---@param err ErrorResponse
55
---@return string?
66
function M.fmt_error(err)
7-
local body = err.body
7+
local body = err.body or {}
88
if body.error and body.error.showUser then
99
local msg = body.error.format
1010
for key, val in pairs(body.error.variables or {}) do

tests/utils_spec.lua

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local utils = require('dap.utils')
2+
13
describe('utils.index_of', function()
24
it('returns index of first item where predicate matches', function()
35
local result = require('dap.utils').index_of(
@@ -79,4 +81,11 @@ describe('utils.fmt_error', function ()
7981
}
8082
}))
8183
end)
84+
85+
it('can handle response without body part', function()
86+
local result = utils.fmt_error({
87+
message = 'Bad things happen',
88+
})
89+
assert.are.same('Bad things happen', result)
90+
end)
8291
end)

0 commit comments

Comments
 (0)