Capturing Traceback With Pcall and Yielding

local function A()
	wait(0.1)
	error("Some error")
end

local function B()
	A()
end


--Right error, no traceback.
local Worked,Error = pcall(B)
if not Worked then
	warn(Error)
	print(debug.traceback())
end

--Wrong error (xpcall can't yield).
xpcall(B,function(Error)
	warn(Error)
	print(debug.traceback())
end)

I am trying to create a new plugin that properly captures the traceback of an error, however I can’t assume there will be no yielding with the functions I need to pcall. Using pcall hides the traceback and xpcall can’t yield. Is there any alternatives that would work for this?

Is this event something that could work for you?

https://developer.roblox.com/api-reference/event/ScriptContext/Error

1 Like

Unfortunately, it doesn’t look like it. The project this is for is a unit testing plugin, which will run these in parallel. I don’t see a good way to use the event to map the error to the correct test running, since there may be no script context or multiple per script.

Edit: Maybe it can work if I either use Error:Wait() or connect it and “grab” the latest output and hope that I don’t run into any concurrency problems. I will update or post when I test that.

Edit 2: I am not sure why I didn’t try to search “yxpcall”. I found a thread by Corecii that has a workable solution. I should be able to modify it for my use case.

1 Like