This PR addresses the issue of Rage failing with a "cannot load such file" exception when an invalid environment name is provided. Instead of the generic error, this PR introduces a custom error with a meaningful message indicating that the specified environment could not be found.
Issue Addressed
Issue: Unknown environment error
Rage creates new applications with three environments: development, production, and test. These environments are configured inside the config/environments folder.
The environment can be set using either the -e option or the RAGE_ENV environment variable.
Example: bundle exec rage s -e production
Example: RAGE_ENV=production bundle exec rage s
If a user makes a typo in the environment name, e.g., “producion”, Rage will fail with the “cannot load such file” exception.
The goal is to raise a custom error with a meaningful message, e.g., “The environment could not be found”.
Changes Made
Error Handling in setup.rb:
Wrapped the require_relative call in a begin...rescue block.
Caught the LoadError and raised a LoadError with a custom message indicating the invalid environment name.
RSpec Test:
Added tests to check if the custom error is raised correctly when an invalid environment name is provided.
Screenshots
Before
After
Documentation
No documentation changes are necessary as this update enhances error handling for existing functionality.
Unknown Environment Error Handling
Description
This PR addresses the issue of Rage failing with a "cannot load such file" exception when an invalid environment name is provided. Instead of the generic error, this PR introduces a custom error with a meaningful message indicating that the specified environment could not be found.
Issue Addressed
config/environments
folder.-e
option or theRAGE_ENV
environment variable.bundle exec rage s -e production
RAGE_ENV=production bundle exec rage s
Changes Made
Error Handling in
setup.rb
:require_relative
call in abegin...rescue
block.LoadError
and raised aLoadError
with a custom message indicating the invalid environment name.RSpec Test:
Screenshots
Before
After
Documentation
No documentation changes are necessary as this update enhances error handling for existing functionality.