'cannot resume non-suspended coroutine' after 'attempt to yield across metamethod/C-call boundary'

Lua does not allow coroutine.yield to be used in C-callbacks or metamethods. This is a reasonable restriction.

For example, the following code triggers an error:

print("pre")
table.sort({1, 2}, function()
	print("before")
	wait(2)
	print("after")
end)
print("this will not be reached")

22:36:33.006 - attempt to yield across metamethod/C-call boundary
22:36:33.006 - Script ‘ServerScriptService.Script’, Line 4
22:36:33.006 - Script ‘ServerScriptService.Script’, Line 2

However, ROBLOX does not register that this yield has failed. As a result, two seconds later, the following error message is printed:

22:36:35.023 - cannot resume non-suspended coroutine
22:36:35.024 - Script ‘ServerScriptService.Script’, Line 4
22:36:35.024 - Script ‘ServerScriptService.Script’, Line 2
22:36:35.024 - Stack End

This 2nd error message cannot be caught (e.g., by pcall), so its clutter cannot be avoided. It doesn’t belong – the error message is misleading at best (since it’s ROBLOX’s fault, not the developer’s), and it displaces the first, real error message that already explained the problem.

ROBLOX should not try to resume a thread that it failed to yield via wait().

7 Likes