Skip to content

Conversation

oneiros
Copy link
Contributor

@oneiros oneiros commented Jul 9, 2025

Fixes #35303

In the above issue it was noted that you can no longer run RAILS_ENV=production bin/rails assets:precompile without access to redis.

The code already accounted for the fact, that the database might not be available, but it did not recognize that the same might be true for the cache backend.

I had initially hoped I could just add a redis error to the list, and indeed the redis gem has its own error type for connection errors. But we use the "hiredis" driver which is a C extension that in some instances just raises RuntimeError.

I could have added Redis::CannotConnectError, Redis::ConnectionError (what is the difference, I wonder?) and RuntimeError. But I figured that a) once you include RuntimeError you are already casting a very wide net and b) there might be other errors (from AR, redis or even other places) that could be applicable here. So I decided to use the catch-all and rescue from all kinds of StandardError.

On the one hand, this is considered bad practice because it can mask all kinds of errors one would rather catch as early as possible. On the other hand, this is "only" an initializer and the method in question is also excersized elsewhere, including in tests.

At initialization time this can fail in all sorts of ways. Apart
from ActiveRecord, there is also the rails cache that in
`production` needs redis. This can raise a couple of errors if
a connection is not possible, including `RuntimeError`.
@oneiros oneiros added ruby Pull requests that update Ruby code to backport PR needed to be backported labels Jul 9, 2025
@oneiros oneiros requested a review from a team July 9, 2025 14:01
@ClearlyClaire ClearlyClaire added this pull request to the merge queue Jul 9, 2025
Merged via the queue into main with commit 786b12e Jul 9, 2025
37 checks passed
@ClearlyClaire ClearlyClaire deleted the fixes/initializer-needing-cache branch July 9, 2025 14:36
@ClearlyClaire ClearlyClaire removed the to backport PR needed to be backported label Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4.4.0 assets:precompile fails trying to.. talk to redis?
2 participants