Debug.traceback() not showing the traceback

I have this function to intercept errors:

game:GetService("ScriptContext").Error:Connect(function(Error)
	warn(Error)
	print(debug.traceback())
end)

An error is occurring in a function that is at the 4th level of the call stack.

However, debug.traceback() is not showing the stack, just the current line of the print(debug.traceback()) statement itself:

image

image

What could be wrong?

Try this:


function DebugTest(Err)
  warn(Err)
  print(debug.traceback())
end

game:GetService("ScriptContext").Error:Connect(DebugTest)

Results:
image

Can you try using the second “level” parameter and see of that helps? I do believe that the default is level 1 so it just returns the first instance of the traceback call.

@Tengarapatu @3gData tks but both suggestions make no difference.
I’ve open a bug report:

Hello. I figured out the issue. It is because the connected function is not a part or the thread encountering the error, it is a completely new function created within and connected to the event of game:GetService("ScriptContext").Error. You are advised to use the second parameter of the Error EventEmitter. It is the default way to get the stack trace.

game:GetService("ScriptContext").Error:Connect(function(message, trace, script)
	print(script:GetFullName().." errored!")
	print("Reason: "..message)
	print("Trace: "..trace)
end)

Hope this helps! :grinning_face_with_smiling_eyes:

1 Like