Skip to content

show error in logs when sourceMaps are set incorrectly#314

Closed
jpeletier wants to merge 3 commits intoactboy168:masterfrom
vworlds:fix-luajit-vars
Closed

show error in logs when sourceMaps are set incorrectly#314
jpeletier wants to merge 3 commits intoactboy168:masterfrom
vworlds:fix-luajit-vars

Conversation

@jpeletier
Copy link
Copy Markdown
Contributor

Thank you for this project, it is a hidden gem. I have just found about it and now I can debug my Lua code!

This PR is a small fix so that variables are shown in the VSCode debugger VARIABLES window when debugging a LuaJIT target.

The following error was shown in the logs:

[ERROR]ERROR:...lua-debug-2.0.12-linux-x64/script/backend/worker/variables.lua:142: attempt to compare number with nil

rdebug.getinfo(frameId, "r", info) is not implemented for LuaJIT, so ftransfer and ntransfer are not populated.

With this fix I can now inspect all the variables, globals and upvalues!

@actboy168
Copy link
Copy Markdown
Owner

Why did you arrive here? This function should only be executed by Lua5.4.

if LUAVERSION >= 54 then
varCreateScopes(frameId, scopes, "Return", false)
end

@jpeletier
Copy link
Copy Markdown
Contributor Author

jpeletier commented Apr 7, 2025

Thank you for the clue. I found the issue.
The problem is for some reason my sourceMaps configuration, which should be an array of pairs, was improperly configured:

			"sourceMaps": [
				[	 
					"${workspaceFolder}/*"
				]
			],

This made the code in

for _, pattern in ipairs(config.sourceMaps) do
local sm = {}
sm[1] = ('^%s$'):format(fs.source_native(fs.source_normalize(pattern[1])):gsub('[%^%$%(%)%%%.%[%]%+%-%?]', '%%%0'))
if sm[1]:find '%*' then
sm[1] = sm[1]:gsub('%*', '(.*)')
end
sm[2] = fs.path_normalize(pattern[2])
sourceMaps[#sourceMaps + 1] = sm

throw an exception, since pattern[2] was nil.

Then, the code you mention was defaulting to LUAVERSION = 54 since the initialization function was not called and did not have the chance to update the value to 51 for luajit.

I repurposed the PR so the configuration is now checked. If the user forgets to add the mapping, it will throw a useful error in the logs:

if pattern[1] == nil or pattern[2] == nil then
    error(("Invalid source map entry. Check sourceMaps property in launch.json, entry #%d"):format(i - 1))
end

@jpeletier jpeletier changed the title fix variables not showing in debugger when using LuaJIT show error in logs when sourceMaps are set incorrectly Apr 7, 2025
@actboy168
Copy link
Copy Markdown
Owner

Thank you. But it is still difficult for users to easily perceive errors when initializing the backend. A better approach is to check on the frontend.
6f98ba2

@jpeletier
Copy link
Copy Markdown
Contributor Author

Ah, wonderful. I didn't know about that part of the code.
Problem solved! Thanks!

@jpeletier jpeletier closed this Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants