Skip to content

Commit

Permalink
Compatibility for updated error classes in Trilogy driver from PR#15
Browse files Browse the repository at this point in the history
There is a new generic Trilogy::ClientError class established with
this PR which is useful to provide full AR 7.0 support:
trilogy-libraries/trilogy#15
  • Loading branch information
lorint committed Jan 16, 2023
1 parent 533e425 commit 711a689
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/trilogy_adapter/backwards_ar_compatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ def with_raw_connection(allow_retry: false, uses_transaction: true)
materialize_transactions if uses_transaction
begin
yield @raw_connection
rescue StandardError => exception
@verified = false unless exception.is_a?(Deadlocked) || exception.is_a?(LockWaitTimeout) ||
# Timed out while in a transaction
((@raw_connection.server_status & 1).positive? &&
exception.is_a?(Errno::ETIMEDOUT))
rescue StandardError => e
@verified = false unless e.is_a?(Deadlocked) || e.is_a?(LockWaitTimeout) ||
( # Timed out while in a transaction?
(@raw_connection.server_status & 1).positive? &&
(e.is_a?(Trilogy::ClientError) || e.is_a?(Errno::ETIMEDOUT))
)
raise
end
end
Expand Down Expand Up @@ -222,3 +223,12 @@ def initialize(connection_class, db_config, *args)
end
end
end

# A do-nothing placeholder allowing AR 7.0 to function when the Trilogy driver is not patched with PR#15:
# https://github.com/github/trilogy/pull/15
class ::Trilogy
unless const_defined?('ClientError')
class ClientError < ::StandardError
end
end
end

0 comments on commit 711a689

Please sign in to comment.