Xpcall still cannot yield across metamethod/C-call boundary

pcall is fixed happy dance, but xpcall still isn’t. :frowning:

Code to replicate:

function handle(err)
    return "ERROR: " .. err:gsub("(.-:)","")
end
 
function f()
    local a = 0
	wait(1)
    return a+1
end
 
print(xpcall(f,handle))
1 Like

xpcall isn’t allowed to yield,

ypcall is. (yield protected call)

Why pcall does allow yielding, I don’t know, because it shouldn’t.

Just use ypcall if you want to yield and also get the error.

local check,error = ypcall(function() end)
if not check then
print(error)
end

xpcall allows for custom error handlement, which I would love to use. But, it doesn’t yield. But yes, ROBLOX patched pcall to yield.

1 Like

I was about to make a post about this but this one already exists. xpcall can’t yield, ypcall is obsolete, pcall can yield. xpcall should be able to yield like pcall can, otherwise I have to overwrite xpcall myself like this

local function xpcall(f, handler) -- yielding xpcall
	local success, response = pcall(f) -- regular pcall can yield, xpcall can't
	if success then
		return true, response
	else
		return false, handler(response)
	end
end
2 Likes