tomblind / local-lua-debugger-vscode

Local Lua Debugger for VSCode
MIT License
106 stars 26 forks source link

`getPrintableValue` crashes debug session on `tostring` #34

Closed martincohen closed 3 years ago

martincohen commented 3 years ago

When debugging with metatables that override __tostring the table might end up in a state when __tostring crashes (for example nil properties not being expected to be nil after full constructor is executed). I've fixed my local version of the lldebugger.lua with a pcall like this:

    local function getPrintableValue(value)
        local valueType = type(value)
        if valueType == "string" then
            return ("\"" .. tostring(value)) .. "\""
        elseif ((valueType == "number") or (valueType == "boolean")) or (valueType == "nil") then
            return tostring(value)
        else
            local _, x = pcall(tostring, value) -- FIX HERE
            return ("[" .. x) .. "]"
        end
    end

Proper fix would be to do the fix in send.ts but since I don't have time to setup full ts build yet, I'm posting here for anyone who might have a similar issue.