Skip to content

Always declare ErrorResponseController class to pass zeitwerk check#33

Open
wilfison wants to merge 1 commit intobjorntrondsen:masterfrom
wilfison:fix-zeitwerk-check
Open

Always declare ErrorResponseController class to pass zeitwerk check#33
wilfison wants to merge 1 commit intobjorntrondsen:masterfrom
wilfison:fix-zeitwerk-check

Conversation

@wilfison
Copy link
Copy Markdown
Contributor

The problem

In a rails project, running rails zeitwerk:check complains that the error_response_controller.rb file is not defining a constant that matches the path expected by the autoloader.

rails zeitwerk:check                
# Hold on, I am eager loading the application.
# expected file /ruby/3.4.1/lib/ruby/gems/3.4.0/bundler/gems/rails_exception_handler/app/controllers/error_response_controller.rb to define constant ErrorResponseController, but didn't

The solution

Always define the class and only conditionally activate actions. This ensures that the autoloader is satisfied.

@bjorntrondsen
Copy link
Copy Markdown
Owner

Most of the codebase here is 13-14 years old. I am currently doing the bare minimum to keep the gem compatible with new releases of Ruby and Rails, until I can find the time to do a full rewrite.
Is this causing any issues for you?

If you only have it enabled in production, then try RAILS_ENV=production rails zeitwerk:check

@wilfison
Copy link
Copy Markdown
Contributor Author

This isn't preventing the application from working properly. However, in the future, I plan to add Zeitwerk verification to CI/CD to ensure the autoloader runs smoothly in any environment.

That's why I tried to make this small fix.

If you plan to rewrite the library, I'm willing to help.

@bjorntrondsen
Copy link
Copy Markdown
Owner

If you plan to rewrite the library, I'm willing to help.

That's very nice of you to offer - I will try to remember that if we decide to go for it

I'll have a look at this patch too

@wilfison
Copy link
Copy Markdown
Contributor Author

wilfison commented Nov 27, 2025

If you only have it enabled in production, then try RAILS_ENV=production rails zeitwerk:check

If you think this fix isn't good, perhaps you could add a warning to the README to use zeitwerk in production mode, as in the example above.

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