From 4c9be9e4d8045436626e7a1e44385116a75d7164 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 14 Oct 2026 13:30:11 -0600 Subject: [PATCH] RUBY-3982 Enable Lint/UnreachableCode cop Remove the cop's exclusion from .rubocop_todo.yml and fix the two offenses it reported. Sections::PayloadOne.deserialize is a deliberate NotImplementedError stub; delete the abandoned implementation below the raise and widen the signature to match its call site. In the unified test runner, drop a stray raise that made the intended Error::ErrorMismatch raise unreachable in the isTimeoutError branch. --- .rubocop_todo.yml | 6 ------ lib/mongo/protocol/serializers.rb | 10 +--------- spec/runners/unified/test.rb | 1 - 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 11bb45a214..74c97f2ec8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -55,12 +55,6 @@ Lint/UnderscorePrefixedVariableName: - 'spec/mongo/server/monitor_spec.rb' - 'spec/support/local_resource_registry.rb' -# Offense count: 2 -Lint/UnreachableCode: - Exclude: - - 'lib/mongo/protocol/serializers.rb' - - 'spec/runners/unified/test.rb' - # Offense count: 2 # Configuration parameters: AllowedPatterns. # AllowedPatterns: (?-mix:(exactly|at_least|at_most)\(\d+\)\.times) diff --git a/lib/mongo/protocol/serializers.rb b/lib/mongo/protocol/serializers.rb index 0902fc6fe5..804081569c 100644 --- a/lib/mongo/protocol/serializers.rb +++ b/lib/mongo/protocol/serializers.rb @@ -319,16 +319,8 @@ def self.serialize(buffer, value, max_bson_size = nil, _validating_keys = nil) # @return [ Array ] Deserialized section. # # @since 2.5.0 - def self.deserialize(buffer) + def self.deserialize(buffer, _options = {}) raise NotImplementedError - - start_size = buffer.length - section_size = buffer.get_int32 # get the size - end_size = start_size - section_size - buffer.get_cstring # get the identifier - documents = [] - documents << BSON::Document.from_bson(buffer) until buffer.length == end_size - documents end end end diff --git a/spec/runners/unified/test.rb b/spec/runners/unified/test.rb index ecbde6fef5..6e123c281e 100644 --- a/spec/runners/unified/test.rb +++ b/spec/runners/unified/test.rb @@ -527,7 +527,6 @@ def execute_operation(op, propagate_errors: false) public_send(method_name, op) rescue Mongo::Error, bson_error, Mongo::Auth::Unauthorized, ArgumentError => e if expected_error.use('isTimeoutError') && !e.is_a?(Mongo::Error::TimeoutError) - raise e raise Error::ErrorMismatch, %,Expected TimeoutError ("isTimeoutError") but got #{e}, end # isClientError doesn't actually mean a client error.