Handle standard errors in association generation#1621
Closed
LTe wants to merge 1 commit intoShopify:mainfrom
Closed
Handle standard errors in association generation#1621LTe wants to merge 1 commit intoShopify:mainfrom
LTe wants to merge 1 commit intoShopify:mainfrom
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
KaanOzkan
requested changes
Aug 28, 2023
| add_error(<<~MSG.strip) | ||
| Cannot generate association `#{declaration(reflection)}` on `#{constant}` since the constant `#{error.class_name}` does not exist. | ||
| MSG | ||
| rescue StandardError => error |
Contributor
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?
Contributor
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
Contributor
Author
There was a problem hiding this comment.
I think you are right and it should be fixed in the monkey-patch for rails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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