diff options
author | Jeremy Daer <jeremydaer@gmail.com> | 2017-10-08 16:14:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-08 16:14:02 -0700 |
commit | 34d12d1483236f997125e2b1f17b96e76fdff99b (patch) | |
tree | aeab3d0beb5db79c95f7390e9a21bb02f2d40223 /actioncable/lib/action_cable | |
parent | 00f2d39c2e3111bf695aed9335388f0e06904d6a (diff) | |
parent | 55a2c101b2889710e1591c9adc15e4d5ca7fb126 (diff) | |
download | rails-34d12d1483236f997125e2b1f17b96e76fdff99b.tar.gz rails-34d12d1483236f997125e2b1f17b96e76fdff99b.tar.bz2 rails-34d12d1483236f997125e2b1f17b96e76fdff99b.zip |
Merge pull request #30757 from jeremy/optional-dependency-hellscape
Adapters bubble up gem version mismatches for their dependencies
Diffstat (limited to 'actioncable/lib/action_cable')
-rw-r--r-- | actioncable/lib/action_cable/server/configuration.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/actioncable/lib/action_cable/server/configuration.rb b/actioncable/lib/action_cable/server/configuration.rb index 82fed81a18..26209537df 100644 --- a/actioncable/lib/action_cable/server/configuration.rb +++ b/actioncable/lib/action_cable/server/configuration.rb @@ -25,13 +25,26 @@ module ActionCable # Also makes sure proper dependencies are required. def pubsub_adapter adapter = (cable.fetch("adapter") { "redis" }) + + # Require the adapter itself and give useful feedback about + # 1. Missing adapter gems and + # 2. Adapter gems' missing dependencies. path_to_adapter = "action_cable/subscription_adapter/#{adapter}" begin require path_to_adapter - rescue Gem::LoadError => e - raise Gem::LoadError, "Specified '#{adapter}' for Action Cable pubsub adapter, but the gem is not loaded. Add `gem '#{e.name}'` to your Gemfile (and ensure its version is at the minimum required by Action Cable)." rescue LoadError => e - raise LoadError, "Could not load '#{path_to_adapter}'. Make sure that the adapter in config/cable.yml is valid. If you use an adapter other than 'postgresql' or 'redis' add the necessary adapter gem to the Gemfile.", e.backtrace + # We couldn't require the adapter itself. Raise an exception that + # points out config typos and missing gems. + if e.path == path_to_adapter + # We can assume that a non-builtin adapter was specified, so it's + # either misspelled or missing from Gemfile. + raise e.class, "Could not load the '#{adapter}' Action Cable pubsub adapter. Ensure that the adapter is spelled correctly in config/cable.yml and that you've added the necessary adapter gem to your Gemfile.", e.backtrace + + # Bubbled up from the adapter require. Prefix the exception message + # with some guidance about how to address it and reraise. + else + raise e.class, "Error loading the '#{adapter}' Action Cable pubsub adapter. Missing a gem it depends on? #{e.message}", e.backtrace + end end adapter = adapter.camelize |