aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2018-12-21 11:43:35 -0500
committerGitHub <noreply@github.com>2018-12-21 11:43:35 -0500
commitb00e46bd6d399d3b8c4707ede0716c3ec2c39eb7 (patch)
tree6f0dcf689e5d3bc181967805f9ec062b8cad8231 /activerecord/lib
parenta84ced1d7c6f469c641b53aced4b16d4e3a3c6fa (diff)
parent22a1265828d9f743b8348fe53424fffb60d6d824 (diff)
downloadrails-b00e46bd6d399d3b8c4707ede0716c3ec2c39eb7.tar.gz
rails-b00e46bd6d399d3b8c4707ede0716c3ec2c39eb7.tar.bz2
rails-b00e46bd6d399d3b8c4707ede0716c3ec2c39eb7.zip
Merge pull request #34753 from eileencodes/raise-less-confusing-error-if-handler-doesnt-exist
Raise helpful error when role doesn't exist
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_handling.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb
index 558cdeccf2..4a941055d1 100644
--- a/activerecord/lib/active_record/connection_handling.rb
+++ b/activerecord/lib/active_record/connection_handling.rb
@@ -158,6 +158,10 @@ module ActiveRecord
end
def with_handler(handler_key, &blk) # :nodoc:
+ unless ActiveRecord::Base.connection_handlers.keys.include?(handler_key)
+ raise ArgumentError, "The #{handler_key} role does not exist. Add it by establishing a connection with `connects_to` or use an existing role (#{ActiveRecord::Base.connection_handlers.keys.join(", ")})."
+ end
+
handler = lookup_connection_handler(handler_key)
swap_connection_handler(handler, &blk)
end