Skip to content

RUBY-2355 Use server error codes in place of error messages when possible #2064

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions lib/mongo/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,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