Yielding causes pcall to output errors

expected behavior is that if an error occurs inside a pcall, it is not sent to the output. If a yield occurs before the error, however, then the pcall does output the error.

repro:
pcall(function() error() end) – does not output error, as expected
pcall(function() wait() error() end) – outputs error

2 Likes

I thought you weren’t able to yield in a pcall; that was why yieldable-pcall (ypcall) was added. Was there an update that changed this behavior?

yes, and now ypcall isn’t documented anywhere.

It seems like this change was quite a while ago. Now I kind of feel late and old… Also: Functions that yield still print errors to output in a pcall

Some time ago, they basically made pcall the same as ypcall. Of all the protected calls, only xpcall still cares about yielding, which is fine.

Would indeed be nice if pcall/ypcall would silence those post-yield error messages. As long as coroutine.resume doesn’t get altered and still outputs errors after yielding.

1 Like

As a developer I want to use LogService to handle errors which have not yet been handled. As pcall/ypcall still unintuitively outputs the error when the protected thread has yielded it makes this quite a frustrating process.

Even without LogService this behaviour is incredibly confusing as it makes it a headache to figure out if an error has been handled when looking at the ouput. If I see an error make it to the output I expect that it is because I have not properly caught it and it is something I should probably try to fix; some errors can only (elegantly) be caught with pcall meaning I either have to mess my code up or live with handled errors making their way to the output, disguising the dangerous unhandled errors.

2 Likes