Skip to content

Commit

Permalink
RUBY-2355 Use server error codes in place of error messages when poss…
Browse files Browse the repository at this point in the history
…ible (#2064)

Co-authored-by: Oleg Pudeyev <oleg@bsdpower.com>
  • Loading branch information
p-mongo and p committed Aug 17, 2020
1 parent 56aa480 commit 04dae97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lib/mongo/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,12 @@ def drop(opts = {})
}).execute(next_primary(nil, session), client: client)
end
rescue Error::OperationFailure => ex
raise ex unless ex.message =~ /ns not found/
false
# NamespaceNotFound
if ex.code == 26 || ex.code.nil? && ex.message =~ /ns not found/
false
else
raise
end
end

# Find documents in the collection.
Expand Down
10 changes: 5 additions & 5 deletions lib/mongo/error/operation_failure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class OperationFailure < Error
# @since 2.1.1
# @deprecated
def retryable?
write_retryable? || RETRY_MESSAGES.any?{ |m| message.include?(m) }
write_retryable? ||
code.nil? && RETRY_MESSAGES.any?{ |m| message.include?(m) }
end

# Whether the error is a retryable error according to the modern retryable
Expand All @@ -110,19 +111,18 @@ def retryable?
#
# @since 2.4.2
def write_retryable?
WRITE_RETRY_MESSAGES.any? { |m| message.include?(m) } ||
write_retryable_code?
write_retryable_code? ||
code.nil? && WRITE_RETRY_MESSAGES.any? { |m| message.include?(m) }
end

def write_retryable_code?
private def write_retryable_code?
if code
WRITE_RETRY_ERRORS.any? { |e| e[:code] == code }
else
# return false rather than nil
false
end
end
private :write_retryable_code?

# Error codes and code names that should result in a failing getMore
# command on a change stream NOT being resumed.
Expand Down

0 comments on commit 04dae97

Please sign in to comment.