Skip to content

Commit

Permalink
Preserve DatabaseError constant
Browse files Browse the repository at this point in the history
#15 changed the error class for
TRILOGY_ERR from `DatabaseError` to `ProtocolError`. This commit
reintroduces `DatabaseError` as an ancestor of `ProtocolError` for
compatibility reasons, so that rescuing `DatabaseError` still works as
before.

Note that even with this change there are a number of error codes (see
ProtocolError::ERROR_CODES) that are no longer `DatabaseError`s, since
we have explicitly recategorized them as `BaseConnectionError`,
`TimeoutError`, or `QueryError`.
  • Loading branch information
composerinteralia committed Feb 28, 2023
1 parent 67c3740 commit 6447ecc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions contrib/ruby/lib/trilogy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ def initialize(error_message = nil, error_code = nil)
end
end

# DatabaseError was replaced by ProtocolError, but we'll keep it around as an
# ancestor of ProtocolError for compatibility reasons (e.g. so `rescue DatabaseError`
# still works. We can remove this class in the next major release.
module DatabaseError
end

class ProtocolError < BaseError
include DatabaseError

ERROR_CODES = {
1205 => TimeoutError, # ER_LOCK_WAIT_TIMEOUT
1044 => BaseConnectionError, # ER_DBACCESS_DENIED_ERROR
Expand Down
1 change: 1 addition & 0 deletions contrib/ruby/test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ def test_too_many_connections
end

assert_equal 1040, ex.error_code
assert ex.is_a?(Trilogy::DatabaseError)
ensure
accept_thread.join
fake_server.close
Expand Down

0 comments on commit 6447ecc

Please sign in to comment.