SeleniumHQ/selenium · error · Error::SerializationError
#{name}##{field.name} expected a [key, value] pair, got #{el
Error message
#{name}##{field.name} expected a [key, value] pair, got #{element.inspect} What it means
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.
Source
Thrown at rb/lib/selenium/webdriver/bidi/serialization/record.rb:317
raw.map do |element|
if field.scalar
read_map_entry(field, element, klass)
elsif element.is_a?(::Array)
read_list(field, element, klass)
else
klass.from_json(element)
end
end
end
# A map entry is a `[key, value]` pair. The key is `Ref / text` — an object key
# deserializes, a bare-string key passes through once validated against the arm's
# primitive. The value is the object-only Ref and always deserializes, so a bare scalar
# there is rejected (object_only holds at the value position). A non-pair element is a
# malformed entry and is rejected outright.
def read_map_entry(field, element, klass)
unless element.is_a?(::Array) && element.size == 2
raise Error::SerializationError,
"#{name}##{field.name} expected a [key, value] pair, got #{element.inspect}"
end
key, value = element
key = key.is_a?(::Hash) ? klass.from_json(key) : scalar_value(field, key)
[key, klass.from_json(value)]
end
# A bare scalar at a scalar-tolerant union position must match one of the union's
# scalar-arm primitives (+scalar+ is a primitive name or an array of them); a
# wrong-typed scalar (a number where a string is expected) is a wire error, not
# something to pass through. An unrecognized primitive (none in PRIMITIVE_TYPES) is
# left unchecked, matching the lenient default elsewhere.
def scalar_value(field, value)
expected = Array(field.scalar).flat_map { |primitive| PRIMITIVE_TYPES[primitive] || [] }
return value if expected.empty? || expected.any? { |type| value.is_a?(type) }
raise Error::SerializationError,View on GitHub (pinned to aa36b38e69)
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.
Defensive patterns
Strategy: validation
Validate before calling
def pair?(element) element.is_a?(::Array) && element.size == 2 end
Type guard
def bidi_map_pair?(element) element.is_a?(::Array) && element.size == 2 end
Try / catch
begin
record = SomeRecord.from_json(payload)
rescue Selenium::WebDriver::Error::SerializationError => e
raise unless e.message =~ /expected a .key, value. pair/
warn "malformed map entry: #{e.message}"
end Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Browser or grid emits a malformed map encoding, schema skew on a scalar/map union field, non-conformant BiDi implementation.
Related errors
- #{name} expected an object on the wire, got #{json_payload.i
- #{name}##{field.name} is required but was missing from the r
- #{name}##{field.name} received null but is not nullable
- #{name}##{field.name} expected #{field.list ? 'a list' : 'a
- #{name}##{field.name} expected #{field.primitive}, got #{raw
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/631184616e46e3db.
Report an issue: GitHub.