mattgallagher / CwlPreconditionTesting

A Mach exception handler that allows Swift precondition failures to be caught and tested.
ISC License
175 stars 46 forks source link

Preconditions under Task with Swift Concurrency is not handled #27

Closed brennanMKE closed 11 months ago

brennanMKE commented 2 years ago

The sample package below reproduces the issue. If a precondition fails while running under Swift Concurrency it does not trap the signal which kills the process. The tests cover a couple of functions. One uses a closure and the other is done with async. The unit tests show how precondition is not caught when run as a Task.

mattgallagher commented 11 months ago

I'm going to close this as "not a bug". The reality is that mach exception handling is a strictly synchronous task and that can't really be changed. You need to scope the synchronous code unit that raises the mach exception or you can't catch it.

Looking at the changes made to Amplify, linked in this comment thread, I think that's not a bad approach: if synchronously scoping is too difficult on a higher level, then stub out the preconditionFailure itself – that way you can apply synchronous changes around preconditionFailure wherever it happens to occur.