Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ttstarck committed Oct 30, 2024
1 parent ab48beb commit cc17bd2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
fibered_mysql2 (0.3.1c)
fibered_mysql2 (0.3.1)
em-synchrony (~> 1.0)
rails (>= 6.1, < 7.1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ class << self
def new_client(config)
Mysql2::EM::Client.new(config)
rescue Mysql2::Error => error
if error.error_number == ActiveRecord::ConnectionAdapters::Mysql2Adapter::ER_BAD_DB_ERROR
raise ActiveRecord::NoDatabaseError.db_error(config[:database])
elsif error.error_number == ActiveRecord::ConnectionAdapters::Mysql2Adapter::ER_ACCESS_DENIED_ERROR
raise ActiveRecord::DatabaseConnectionError.username_error(config[:username])
elsif [ActiveRecord::ConnectionAdapters::Mysql2Adapter::ER_CONN_HOST_ERROR, ActiveRecord::ConnectionAdapters::Mysql2Adapter::ER_UNKNOWN_HOST_ERROR].include?(error.error_number)
raise ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
if error.error_number == 1049
raise ActiveRecord::NoDatabaseError.new, error.message
else
raise ActiveRecord::ConnectionNotEstablished, error.message
end
Expand Down
24 changes: 0 additions & 24 deletions spec/unit/fibered_mysql2_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@
end
end

context "when the error is an access denied error" do
let(:error_number) { 1045 }

it "raises a DatabaseConnectionError" do
expect { new_client }.to raise_error(ActiveRecord::DatabaseConnectionError)
end
end

context "when the error is a connection host error" do
let(:error_number) { 2003 }

it "raises a DatabaseConnectionError" do
expect { new_client }.to raise_error(ActiveRecord::DatabaseConnectionError)
end
end

context "when the error is an unknown host error" do
let(:error_number) { 2005 }

it "raises a DatabaseConnectionError" do
expect { new_client }.to raise_error(ActiveRecord::DatabaseConnectionError)
end
end

context "when the error is not a known error" do
let(:error_number) { 1234 }

Expand Down

0 comments on commit cc17bd2

Please sign in to comment.