Debug.traceback doesn't mention the three arguments it can take

There is no mention of the arguments which you can pass to debug.traceback

First argument

The first argument is an optional thread, so you can get the stack trace of another thread.
If the first argument isn’t a thread then it will assume it is the running thread, which will make the first argument act like the second argument and the second argument act like the third argument.

debug.traceback(coroutine.running(),message,level)
--is the same thing as
debug.traceback(message,level)
--and you can pass other threads
local thread = coroutine.create(function()end)
debug.traceback(thread,message,level)
Second argument

The second argument specifies what to be attached to the start of the traceback.
There will automatically be a newline character after the message if the second argument is provided.
If the second argument is nil, no message will be added. If the second argument isn’t nil and not a string/number then debug.traceback will error.

debug.traceback""
--forces newline character infront of the traceback
debug.traceback"traceback:"

image

Third Argument

The third argument controls the level to start the traceback.
The default level is 1, starting the traceback from where debug.traceback is being called.
If level is anything other than nil or a number, debug.traceback will error.

local function f()
    debug.traceback(nil,1)
    --acts the same as
    debug.traceback()

    debug.traceback(nil,2)
    --makes the function call not show up in the traceback
end
f()

With level 1:
image
With level 2:
image

The traceback from debug.traceback also ends with a new line, which isn’t specifically stated.

13 Likes

Any word on this being added?

Thank you for this information.


I’m not entirely sure but it doesn’t seem like the output is taking me to the Script Line that was debug.traceback; for example I’m doing

warn(debug.traceback("Message"))

when I click the output it will always bring me to the line that has warn instead of the BaseScript that is calling the function

is this intentional, a bug or am I doing something wrong?

It looks like the documentation was updated to string debug.traceback ( string message, number level = 1 ). This still doesn’t mention that debug.traceback can take a thread, and it also indicates that message is a required argument (which it isn’t).

Going to bump this because this is really useful information for developers - it would be great if this could be addressed. In my 4 years on Roblox, I only found out about this today! Oh, the many times I had to write string patterns to remove the first N lines…

2 Likes