{"record":{"id":"631184616e46e3db","repo":"SeleniumHQ/selenium","slug":"name-field-name-expected-a-key-value-pair","errorCode":null,"errorMessage":"#{name}##{field.name} expected a [key, value] pair, got #{element.inspect}","messagePattern":"#(.+?)##(.+?) expected a \\[key, value\\] pair, got #(.+?)","errorType":"exception","errorClass":"Error::SerializationError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/bidi/serialization/record.rb","lineNumber":317,"sourceCode":"              raw.map do |element|\n                if field.scalar\n                  read_map_entry(field, element, klass)\n                elsif element.is_a?(::Array)\n                  read_list(field, element, klass)\n                else\n                  klass.from_json(element)\n                end\n              end\n            end\n\n            # A map entry is a `[key, value]` pair. The key is `Ref / text` — an object key\n            # deserializes, a bare-string key passes through once validated against the arm's\n            # primitive. The value is the object-only Ref and always deserializes, so a bare scalar\n            # there is rejected (object_only holds at the value position). A non-pair element is a\n            # malformed entry and is rejected outright.\n            def read_map_entry(field, element, klass)\n              unless element.is_a?(::Array) && element.size == 2\n                raise Error::SerializationError,\n                      \"#{name}##{field.name} expected a [key, value] pair, got #{element.inspect}\"\n              end\n\n              key, value = element\n              key = key.is_a?(::Hash) ? klass.from_json(key) : scalar_value(field, key)\n              [key, klass.from_json(value)]\n            end\n\n            # A bare scalar at a scalar-tolerant union position must match one of the union's\n            # scalar-arm primitives (+scalar+ is a primitive name or an array of them); a\n            # wrong-typed scalar (a number where a string is expected) is a wire error, not\n            # something to pass through. An unrecognized primitive (none in PRIMITIVE_TYPES) is\n            # left unchecked, matching the lenient default elsewhere.\n            def scalar_value(field, value)\n              expected = Array(field.scalar).flat_map { |primitive| PRIMITIVE_TYPES[primitive] || [] }\n              return value if expected.empty? || expected.any? { |type| value.is_a?(type) }\n\n              raise Error::SerializationError,","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/bidi/serialization/record.rb#L299-L335","documentation":"For a BiDi map field (a scalar-typed union serialized as [key, value] pairs), read_map_entry expects each element to be a 2-item Array. An element that is not a 2-element array is malformed and raises Error::SerializationError. This guards the entry-level shape of BiDi map structures.","triggerScenarios":"Inbound BiDi map payload where an element is not a [key, value] pair — e.g. a single scalar, an object, or an array of length != 2 at a position deserialized via read_map_entry.","commonSituations":"Browser or grid emits a malformed map encoding, schema skew on a scalar/map union field, non-conformant BiDi implementation.","solutions":["Capture the raw list to inspect the malformed element.","Confirm the map encoding ([key, value] pairs) is what the browser should emit per spec.","Align Selenium and browser versions.","Report the malformed entry upstream."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def pair?(element)\n  element.is_a?(::Array) && element.size == 2\nend","typeGuard":"def bidi_map_pair?(element)\n  element.is_a?(::Array) && element.size == 2\nend","tryCatchPattern":"begin\n  record = SomeRecord.from_json(payload)\nrescue Selenium::WebDriver::Error::SerializationError => e\n  raise unless e.message =~ /expected a .key, value. pair/\n  warn \"malformed map entry: #{e.message}\"\nend","preventionTips":["Validate each element is a [key, value] pair before deserializing map fields.","Capture raw map payloads to spot malformed encodings.","Align client and browser versions; malformed entries usually indicate non-conformant BiDi."],"tags":["bidi","serialization","map","schema","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}