in generators (and async generators / coroutines, too), exception handling during yield should be done by the generator
Currently in generators, we catch exceptions during the yield and raise them. This is not correct, we should be setting the error and let the frame do the error handling. In other words, the current implementation ignores try blocks when the error happens during yield.
https://github.com/Lightning-AI/lightning-thunder/blob/d15b64c71aca487397c47452ac6872d853d9acda/thunder/core/interpreter.py#L5888-L5894
This is also the only occasion when Python 3.12 reaches the CLEANUP_THROW opcode.
cc @apaz-cli
triage review:
- we can ignore exceptions in some rare generator+exception use cases
- not an urgent problem; no known use cases
- erroring loudly would be too painful here; when we look at this let's just fix it
- we don't have a test in our suite for this kind of thing
So what needs to be done is in the above snippet to call into run_frame but instead of executing the next instruction to immediately jump to the exception handling. Probably just an if in _run_frame and calling _run_frame in the above snippet instead of raising.
Not as urgent.