diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2013-12-24 08:17:21 -0800 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2013-12-24 08:17:21 -0800 |
commit | 9705df5c2bf29058c8e7c8d4fa91b95ffd3a74c9 (patch) | |
tree | 72c33385498a733bba7a74409ea633908ad6d807 /activerecord/lib | |
parent | 959cfcef7255bba720ce3f15323056533ea7b50a (diff) | |
parent | f0311c24876f78ed2054fb1e5a24d38a4d0db4ac (diff) | |
download | rails-9705df5c2bf29058c8e7c8d4fa91b95ffd3a74c9.tar.gz rails-9705df5c2bf29058c8e7c8d4fa91b95ffd3a74c9.tar.bz2 rails-9705df5c2bf29058c8e7c8d4fa91b95ffd3a74c9.zip |
Merge pull request #13469 from schneems/schneems/no-database-errors-all
Raise NoDatabaseError when db does not exist
Diffstat (limited to 'activerecord/lib')
3 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index e790f731ea..6d8e994654 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -18,6 +18,12 @@ module ActiveRecord client = Mysql2::Client.new(config) options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0] ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config) + rescue Mysql2::Error => error + if error.message.include?("Unknown database") + raise ActiveRecord::NoDatabaseError.new(error.message) + else + raise error + end end end diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 760f1435eb..7dbaa272a3 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -34,6 +34,12 @@ module ActiveRecord default_flags |= Mysql::CLIENT_FOUND_ROWS if Mysql.const_defined?(:CLIENT_FOUND_ROWS) options = [host, username, password, database, port, socket, default_flags] ConnectionAdapters::MysqlAdapter.new(mysql, logger, options, config) + rescue Mysql::Error => error + if error.message.include?("Unknown database") + raise ActiveRecord::NoDatabaseError.new(error.message) + else + raise error + end end end diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index a02eda5603..92bb70ba53 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -31,6 +31,12 @@ module ActiveRecord db.busy_timeout(ConnectionAdapters::SQLite3Adapter.type_cast_config_to_integer(config[:timeout])) if config[:timeout] ConnectionAdapters::SQLite3Adapter.new(db, logger, config) + rescue Errno::ENOENT => error + if error.message.include?("No such file or directory") + raise ActiveRecord::NoDatabaseError.new(error.message) + else + raise error + end end end |