Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure syscall error subclasses have an error_code attribute #59

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions contrib/ruby/lib/trilogy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Trilogy
# Trilogy::Error is the base error type. All errors raised by Trilogy
# should be descendants of Trilogy::Error
module Error
attr_reader :error_code
end

# Trilogy::ConnectionError is the base error type for all potentially transient
Expand All @@ -15,8 +16,6 @@ module ConnectionError
class BaseError < StandardError
include Error

attr_reader :error_code

def initialize(error_message = nil, error_code = nil)
message = error_code ? "#{error_code}: #{error_message}" : error_message
super(message)
Expand All @@ -43,8 +42,6 @@ class CastError < ClientError
class TimeoutError < Errno::ETIMEDOUT
include ConnectionError

attr_reader :error_code

def initialize(error_message = nil, error_code = nil)
super
@error_code = error_code
Expand All @@ -53,10 +50,20 @@ def initialize(error_message = nil, error_code = nil)

class ConnectionRefusedError < Errno::ECONNREFUSED
include ConnectionError

def initialize(error_message = nil, error_code = nil)
super
@error_code = error_code
end
end

class ConnectionResetError < Errno::ECONNRESET
include ConnectionError

def initialize(error_message = nil, error_code = nil)
super
@error_code = error_code
end
end

# DatabaseError was replaced by ProtocolError, but we'll keep it around as an
Expand Down