Rescue ActiveSupport::DeprecationException to prevent crashes - #2386
Rescue ActiveSupport::DeprecationException to prevent crashes#2386ndbroadbent wants to merge 1 commit into
Conversation
…en interacting with deprecated module names
|
I have signed the CLA! |
| !mod.singleton_class? && | ||
| ActiveSupport::Concern > mod.singleton_class && | ||
| has_dependencies?(mod) | ||
| rescue ActiveSupport::DeprecationException |
There was a problem hiding this comment.
I'm not sure if this is the right way to go 🙁 . Also, this could theoretically happen with any DSL compiler, and we'd need rescue calls in each one.
I took a look at alternatives, and unfortunately you can't use the --skip-constant option because those constants are still loaded during the gathering phase. I think the only other viable solutions are:
- Not loading the deprecated constant in the first place from your application. If it's not in ObjectSpace after app boot, it won't be accessed by Tapioca's DSL compilers.
- Don't raise deprecation warnings while Tapioca is running. You could detect this by looking at Kernel#caller or through an ENV variable set while running Tapioca.
There was a problem hiding this comment.
I agree, this isn't the right fix.
We already have handling for DeprecatedConstantProxy classes in the gem pipeline, we could implement something similar in the DSL pipeline as well: https://github.com/Shopify/tapioca/blob/main/lib/tapioca/gem/pipeline.rb#L512-L524
|
It looks like this is not going in the right direction. I'll close for now. |
Motivation
This fixes a crash I was seeing with the Dotenv gem. They use ActiveSupport::Deprecation::DeprecatedConstantProxy for their old Railtie module so it blows up if anything touches it (since we raise on deprecation warnings in our app).
Implementation
I added some
begin...rescueblocks to catch any deprecation exceptions and suppress them.Tests
I've added some tests to ensure that tapioca ignores
DeprecationExceptionfor these cases. These are the only locations where it was crashing, and nowtapioca dslruns without errors.Crash Backtrace