Handle standard errors in association generation#1621
Conversation
This commit addresses an issue where standard errors raised during the association generation process were not properly handled, leading to failures in generating RBI files. Now, these errors are captured and logged appropriately, improving the robustness of the association generation process. A new test case has been added to verify this functionality.
bfd540e to
7531af0
Compare
| add_error(<<~MSG.strip) | ||
| Cannot generate association `#{declaration(reflection)}` on `#{constant}` since the constant `#{error.class_name}` does not exist. | ||
| MSG | ||
| rescue StandardError => error |
There was a problem hiding this comment.
We think this rescue is a bit of an overkill for one method missing. Rescuing every error and generating potentially incorrect RBIs with no one noticing it would be a real possibility with this change.
Looking at the monkey patching in the test it seems to break Rails internals that we rely on. Can this be fixed in that monkey patch instead?
There was a problem hiding this comment.
@LTe An alternative is doing an early return if reflection isn't defined similar to https://github.com/Shopify/tapioca/pull/1632/files#diff-56a92ed84ac2571734401e6c2cfd52020ff8b497899c93e07d1effedd7a3bc97R57
There was a problem hiding this comment.
I think you are right and it should be fixed in the monkey-patch for rails.
Motivation
This commit addresses an issue where standard errors raised during the association generation process were not properly handled, leading to failures in generating RBI files. Now, these errors are captured and logged appropriately, improving the robustness of the association generation process. A new test case has been added to verify this functionality.
Implementation
Handle unexpected errors during building reflections. It should just ignore this reflection and move on.
Tests
I added specs