Skip to content

Commit

Permalink
Fix nil body handling in fmt_error
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Sep 24, 2022
1 parent 3c3e0a8 commit 764899d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/dap/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local M = {}
---@param err ErrorResponse
---@return string?
function M.fmt_error(err)
local body = err.body
local body = err.body or {}
if body.error and body.error.showUser then
local msg = body.error.format
for key, val in pairs(body.error.variables or {}) do
Expand Down
9 changes: 9 additions & 0 deletions tests/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local utils = require('dap.utils')

describe('utils.index_of', function()
it('returns index of first item where predicate matches', function()
local result = require('dap.utils').index_of(
Expand Down Expand Up @@ -79,4 +81,11 @@ describe('utils.fmt_error', function ()
}
}))
end)

it('can handle response without body part', function()
local result = utils.fmt_error({
message = 'Bad things happen',
})
assert.are.same('Bad things happen', result)
end)
end)

0 comments on commit 764899d

Please sign in to comment.