Skip to content

Handle standard errors in association generation#1621

Closed
LTe wants to merge 1 commit intoShopify:mainfrom
LTe:active_record-no-method-error
Closed

Handle standard errors in association generation#1621
LTe wants to merge 1 commit intoShopify:mainfrom
LTe:active_record-no-method-error

Conversation

@LTe
Copy link
Copy Markdown
Contributor

@LTe LTe commented Aug 24, 2023

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

@LTe LTe requested a review from a team as a code owner August 24, 2023 15:30
@LTe LTe requested review from Morriar and andyw8 August 24, 2023 15:30
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.
@LTe LTe force-pushed the active_record-no-method-error branch from bfd540e to 7531af0 Compare August 24, 2023 15:31
add_error(<<~MSG.strip)
Cannot generate association `#{declaration(reflection)}` on `#{constant}` since the constant `#{error.class_name}` does not exist.
MSG
rescue StandardError => error
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right and it should be fixed in the monkey-patch for rails.

@LTe LTe closed this Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants