rails icon indicating copy to clipboard operation
rails copied to clipboard

Add warning for non-existent directories in autoload paths for Zeitwerk

Open aeroastro opened this issue 1 year ago • 1 comments

Motivation / Background

This Pull Request has been created because I noticed that Rails does not warn the user when they specify a non-existing directory in the config.autoload_paths or config.autoload_once_paths settings. This can lead to confusion and hard-to-debug errors when the user expects some files to be loaded but they are not.

Detail

This Pull Request add a warning message when specified paths for config.autoload_paths and config.autoload_once_paths are not existing directories. Below is the example message:

config.autoload_paths must be existing directories.
'/wrong/path/to/load' is not an existing directory.

Additional information

Since this PR does not change the behavior itself, I believe existing tests cover this PR.

The warning message has been inspired by the following code. https://github.com/rails/rails/blob/91968e5a185927b8216b82c860a48b6367285456/railties/lib/rails/application/bootstrap.rb#L23-L30

Checklist

Before submitting the PR make sure the following are checked:

  • [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • [ ] Tests are added or updated if you fix a bug or add a feature.
  • [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

aeroastro avatar Jan 11 '24 07:01 aeroastro

I am 👍 on this warning. Indeed, for Zeitwerk, a non-existing directory on setup is an error condition.

However, IIRC the reason Rails is not as strict or emits warnings is that Action Mailer adds test/mailers/previews unconditionally to the autoload paths. It would not be coherent that a Rails component triggers a Rails warning.

What about changing Action Mailer before going for this?

fxn avatar Jan 17 '24 12:01 fxn