Level parameter in error(msg, level) is ignored by hyperlink in output

Issue Type: Display
Impact: Moderate
Frequency: Constantly
Date First Experienced: 2021-02-21 11:02:00 (-06:00)
Date Last Experienced:

This will work on any script.

Repro:
Step 1: Make a script in ServerScriptService
Step 2: Add the following code

local function Method3()
	error("Sample error", 3)
end

local function Method2()
	Method3()
end

local function Method1()
	Method2()
end

Method1()

Step 3: Run the game
Step 4: Observe that when clicking on the red text in the output, studio opens to line 2, not 10.
image

Repro File of issue: Output Hyperlinks Incorrectly Repro.rbxl (21.1 KB)

Expected Behavior:
The red text says the correct location, line 10. However, I expect when clicking on this hyperlink to go to line 10. It should also be noted that if using multiple scripts & ModuleScripts, it will open to the wrong script. The fix is to make the red text’s hyperlink the same as what it says.

Actual Behavior:
Studio’s output ignores the level provided in error(msg, level) and hyperlinks to the wrong place.

Workaround:
Technically, the workaround is just clicking on the proper blue text below. However, it should still be fixed to hyperlink to the place it says it will.

3 Likes

What should clicking on the error go to when the error level is 0?

local function Method3()error("Sample error",0)end
local function Method2()Method3()end
local function Method1()Method2()end
Method1()

image
The error level only controls how information is added to the error object when the error object is a string.
Both of these scripts produce the same error message:

local function Method3()error("ServerScriptService.Script:2: Sample error",0)end
local function Method2()Method3()end
local function Method1()Method2()end
Method1()
local function Method3()error("Sample error",2)end
local function Method2()Method3()end
local function Method1()Method2()end
Method1()

Would these jump to different locations (because they pass different error levels)?

1 Like

I mean, you can produce any text, but the trace added by studio’s output should be respected.

For level 0, I’m not sure, since it hides the actual trace text. An argument could be made it shouldn’t be clickable, since the trace is hidden. It could also just default to level 1 for the hyperlink.

However, if the red text has a trace, clicking it should go to what the trace says, for consistency sake.

Ideally, clicking on text should go where it states, and if it doesnt state anything either it defaults to something, or does nothing.

The error function adds the information, not the output.
Lua 5.1 Reference Manual

Usually, error adds some information about the error position at the beginning of the message. The level argument specifies how to get the error position. With level 1 (the default), the error position is where the error function was called. Level 2 points the error to where the function that called error was called; and so on. Passing a level 0 avoids the addition of error position information to the message.

local function f3(...)error(...)end
local function f2(...)f3(...)end
local function f1(...)f2(...)end
local function f(...)f1(...)end
local s1,e1 = pcall(f,"Sample error",2)
print(s1) --> false
print(e1) --> ServerScriptService.Script:2: Sample error
local s2,e2 = pcall(f,"ServerScriptService.Script:2: Sample error",0)
print(s2) --> false
print(e2) --> ServerScriptService.Script:2: Sample error

Both calls passed different error levels, and the same error message was generated. It wouldn’t be possible to determine which was used based only on the error message.

2 Likes

Good point, but maybe the output has access to other information as well? Could using the stack trace be a way of figuring it out? Even if there are edge cases, it would still be nice to have it link properly, at least with normal use, for consistency sake.

I don’t know how the internals of the output works, but if they are able to link the stack trace properly than maybe they can for the error message itself as well?

If not, that’s fine. That’s probably the reason the current behavior exists right now. I guess we’ll just have to wait for hear from an engineer. Thanks for the insight.

Thanks for the report! We’ve filed a ticket to our internal database and we’ll follow up when we have an update for you.

3 Likes

Hello. The issue here is likely that the hyperlink generator always uses the top callstack entry when the error is synthesized. Unfortunately, fixing it isn’t currently on the roadmap due to there not being any good solution.

2 Likes

Note that this is a duplicate bug report: Clicking in stack trace opens wrong script/line when level parameter is provided

Closing this one in favor of older one (cc @OuterspaceNemo )

2 Likes