Clicking in stack trace opens wrong script/line when level parameter is provided

Description of bug:

Clicking the first message in a stack trace opens up the wrong script/line number when caused by an error statement with a level argument given. The text of the error is as expected, but when clicking it in the Output window, it does not open the editor at the right statement.

Reproduction:

Put the following in a Script in ServerScriptService:

function C(i)
	if i >= 5 then
		error("An error occurred because of something two levels higher", 3)
	end
end

function B(i)
	C(i)
end

function A()
	-- passing an illegal value to B, if there is an error it should refer here:
	local i = 5
	B(i)
end

A()

When running the place, the Output window shows the following:

image

The text displayed here is absolutely correct. Notice that the first line refers to line 14, which is correct because I throw the error with a level of 2, so the error position should be at the A() call, as expected. However, if you click the first line to go to the source where the error occurred, you will actually go to line 3 instead of line 14. This is a bug.

The bug also happens if calls through multiple scripts/modules are performed. Here is a reproduction file for the same example as above, but then with A, B, and C spread over modules instead. The stack trace will say the error occurred in module A at line 5 which is correct, but clicking the first message will open module C at line 3 instead.

Repro_StackTraceLevelBug.rbxl (12.8 KB)

image

Desired behaviour:

The correct script/line should be opened when I click the first stack trace item, as displayed in the text of the stack trace, no matter what level I feed to the error function to cause the stack trace.

6 Likes

Got this snippet from the Lua 5.1.4 source files:

static int luaB_error (lua_State *L) {
  int level = luaL_optint(L, 2, 1);
  lua_settop(L, 1);
  if (lua_isstring(L, 1) && level > 0) {  /* add extra information? */
    luaL_where(L, level);
    lua_pushvalue(L, 1);
    lua_concat(L, 2);
  }
  return lua_error(L);
}

The level thing is purely used for generating the prefix thing. After (optionally) adding that prefix, it calls lua_error, which has no idea about the level argument of error().

in other words: the message is just a message. very difficult to “fix”

It’d be nice to have, though.

Thank you for such a well-written bug report!

We decided not to fix this bug because it’s unclear whether the current behavior or the proposed behavior is more desirable and it would involve a substantial amount of refactoring. We would rather focus our efforts on other issues.

1 Like

Fair enough, thank you for the response