Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for DfE::Analytics crashing on installation #93

Merged
merged 6 commits into from
Oct 27, 2023

Conversation

ericaporter
Copy link
Contributor

@ericaporter ericaporter commented Oct 17, 2023

Relating to this ticket: https://trello.com/c/ApoCu21a/1381-dfeanalytics-crashes-on-installation There is a bug where the gem crashes on installation

Investigation: Identified the release, PR and then commit which appears to be causing the problem 52486c5

It would seem that after adding def self.initialize! and DfE::Analytics::Fields.check! the generators are not running first and the following error message could be observed:
Screenshot 2023-10-17 at 12 25 26

@asatwal, I have gone for adding a check in the initialization method, returning unless dfe_analytics.rb exists (actually if we go for this solution, it might be better to have a check for all the files the generator should create including the three .yml files).

I know there are a few ways we could tackle this one but this seemed like the most straightforward - keen to know if you think it will be sufficient.

Testing the fix: in ECF, in a demo app I spun up to investigate this issue, in Register and in Apply (all locally)

I uninstalled and installed the gem with my fix (pointing to my branch)

Interestingly the fix did not work in either Apply or Register, but that is because of some legacy config in application.rb (config.analytics = config_for(:analytics)) which predates the gem.

I don’t think this matters, it is only worth noting that if there is a service that has this config that tries to install the gem, it might still crash on installation, but removing this config would fix the problem.

Might be worth making apply and register aware of the legacy config so they can remove it.

@ericaporter ericaporter added the Do not merge Not ready for merging label Oct 17, 2023
@ericaporter ericaporter requested a review from asatwal October 17, 2023 11:33
asatwal
asatwal previously approved these changes Oct 17, 2023
Copy link
Collaborator

@asatwal asatwal left a comment

Choose a reason for hiding this comment

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

👍 This seems like the simplest check we can do and it fixes the issue and it is sufficient to check just one of the generated files.

Nice work !

@asatwal asatwal dismissed their stale review October 18, 2023 07:46

On second thoughts do we need this for Production ?

Comment on lines 98 to 101
unless File.exist?(Rails.root.join('config/initializers/dfe_analytics.rb'))
Rails.logger.info('Warning: DfE Analytics is not set up. Run `bundle exec rails generate dfe:analytics:install')
return
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just had a second thought on this. Is this required for Production ? And should we write to the terminal ?

Suggested change
unless File.exist?(Rails.root.join('config/initializers/dfe_analytics.rb'))
Rails.logger.info('Warning: DfE Analytics is not set up. Run `bundle exec rails generate dfe:analytics:install')
return
end
if !Rails.env.production? && !File.exist?(Rails.root.join('config/initializers/dfe_analytics.rb'))
message = "Warning: DfE Analytics is not set up. Run: 'bundle exec rails generate dfe:analytics:install'"
Rails.logger.info(message)
puts message
return
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good plan!

unless Rails.env.production? || File.exist?(Rails.root.join('config/initializers/dfe_analytics.rb'))
message = "Warning: DfE Analytics is not set up. Run: 'bundle exec rails generate dfe:analytics:install'"
Rails.logger.info(message)
puts message
return
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For my brain, unless || is easier to read but happy to update to if !

Copy link
Contributor

Choose a reason for hiding this comment

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

Randomly saw this. First time I see unless || described as easier to read 😅. I personally avoid it.

Copy link
Contributor Author

@ericaporter ericaporter Oct 27, 2023

Choose a reason for hiding this comment

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

Ha, well, imo it follows the pattern with the other unless just above it, plus I think easier than if doesn't && doesn't @vassyz, but I shall bear that in mind next time I use unless

asatwal
asatwal approved these changes Oct 23, 2023
@ericaporter ericaporter removed the Do not merge Not ready for merging label Oct 25, 2023
@ericaporter ericaporter merged commit fe73499 into main Oct 27, 2023
7 checks passed
@ericaporter ericaporter deleted the debug-installation branch October 27, 2023 07:59
@ericaporter ericaporter mentioned this pull request Nov 17, 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.

3 participants