forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #531 from rails/main
Create a new pull request by comparing changes across two branches
- Loading branch information
Showing
95 changed files
with
2,890 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
activerecord/lib/active_record/connection_adapters/trilogy/errors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveRecord | ||
module ConnectionAdapters | ||
module Trilogy | ||
module Errors | ||
# ServerShutdown will be raised when the database server was shutdown. | ||
class ServerShutdown < ActiveRecord::ConnectionFailed | ||
end | ||
|
||
# ServerLost will be raised when the database connection was lost. | ||
class ServerLost < ActiveRecord::ConnectionFailed | ||
end | ||
|
||
# ServerGone will be raised when the database connection is gone. | ||
class ServerGone < ActiveRecord::ConnectionFailed | ||
end | ||
|
||
# BrokenPipe will be raised when a system process connection fails. | ||
class BrokenPipe < ActiveRecord::ConnectionFailed | ||
end | ||
|
||
# SocketError will be raised when Ruby encounters a network error. | ||
class SocketError < ActiveRecord::ConnectionFailed | ||
end | ||
|
||
# ConnectionResetByPeer will be raised when a network connection is closed | ||
# outside the sytstem process. | ||
class ConnectionResetByPeer < ActiveRecord::ConnectionFailed | ||
end | ||
|
||
# ClosedConnection will be raised when the Trilogy encounters a closed | ||
# connection. | ||
class ClosedConnection < ActiveRecord::ConnectionFailed | ||
end | ||
|
||
# InvalidSequenceId will be raised when Trilogy ecounters an invalid sequence | ||
# id. | ||
class InvalidSequenceId < ActiveRecord::ConnectionFailed | ||
end | ||
|
||
# UnexpectedPacket will be raised when Trilogy ecounters an unexpected | ||
# response packet. | ||
class UnexpectedPacket < ActiveRecord::ConnectionFailed | ||
end | ||
end | ||
end | ||
end | ||
end |
64 changes: 64 additions & 0 deletions
64
...ord/lib/active_record/connection_adapters/trilogy/lost_connection_exception_translator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveRecord | ||
module ConnectionAdapters | ||
module Trilogy | ||
class LostConnectionExceptionTranslator | ||
attr_reader :exception, :message, :error_number | ||
|
||
def initialize(exception, message, error_number) | ||
@exception = exception | ||
@message = message | ||
@error_number = error_number | ||
end | ||
|
||
def translate | ||
translate_database_exception || translate_ruby_exception || translate_trilogy_exception | ||
end | ||
|
||
private | ||
ER_SERVER_SHUTDOWN = 1053 | ||
CR_SERVER_LOST = 2013 | ||
CR_SERVER_LOST_EXTENDED = 2055 | ||
CR_SERVER_GONE_ERROR = 2006 | ||
|
||
def translate_database_exception | ||
case error_number | ||
when ER_SERVER_SHUTDOWN | ||
Errors::ServerShutdown.new(message) | ||
when CR_SERVER_LOST, CR_SERVER_LOST_EXTENDED | ||
Errors::ServerLost.new(message) | ||
when CR_SERVER_GONE_ERROR | ||
Errors::ServerGone.new(message) | ||
end | ||
end | ||
|
||
def translate_ruby_exception | ||
case exception | ||
when Errno::EPIPE | ||
Errors::BrokenPipe.new(message) | ||
when SocketError, IOError | ||
Errors::SocketError.new(message) | ||
when ::Trilogy::ConnectionError | ||
if message.include?("Connection reset by peer") | ||
Errors::ConnectionResetByPeer.new(message) | ||
end | ||
end | ||
end | ||
|
||
def translate_trilogy_exception | ||
return unless exception.is_a?(::Trilogy::Error) | ||
|
||
case message | ||
when /TRILOGY_CLOSED_CONNECTION/ | ||
Errors::ClosedConnection.new(message) | ||
when /TRILOGY_INVALID_SEQUENCE_ID/ | ||
Errors::InvalidSequenceId.new(message) | ||
when /TRILOGY_UNEXPECTED_PACKET/ | ||
Errors::UnexpectedPacket.new(message) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.