{"record":{"id":"6e71db3d7b4b4d57","repo":"SeleniumHQ/selenium","slug":"name-field-name-expected-field-primitive","errorCode":null,"errorMessage":"#{name}##{field.name} expected #{field.primitive}, got #{raw.inspect}","messagePattern":"#(.+?)##(.+?) expected #(.+?), got #(.+?)","errorType":"exception","errorClass":"Error::SerializationError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/bidi/serialization/record.rb","lineNumber":288,"sourceCode":"\n              raise Error::SerializationError,\n                    \"#{name}##{field.name} expected #{field.list ? 'a list' : 'a single value'}, got #{raw.inspect}\"\n            end\n\n            # Ruby classes a checkable primitive admits. `number` is any Numeric (JSON has one\n            # number type); `integer` requires an Integer — a browser emits `5`, not `5.0`, for an\n            # integer (JS has no int/float split), so this rarely false-positives yet still rejects\n            # a genuine non-integer like 1.5. A field with no primitive descriptor is left unchecked.\n            PRIMITIVE_TYPES = {\n              'string' => [::String], 'boolean' => [::TrueClass, ::FalseClass],\n              'number' => [::Numeric], 'integer' => [::Integer]\n            }.freeze\n\n            def check_primitive(field, raw)\n              expected = PRIMITIVE_TYPES[field.primitive]\n              return if expected.nil? || expected.any? { |type| raw.is_a?(type) }\n\n              raise Error::SerializationError, \"#{name}##{field.name} expected #{field.primitive}, got #{raw.inspect}\"\n            end\n\n            def enum_hash(field)\n              (@enums ||= {})[field.name] ||= Protocol.const_get(field.enum)\n            end\n\n            # Parses each element. A `scalar` field is a map encoded as `[key, value]` pairs, so\n            # every element must be a 2-item pair — each is read as one, and a malformed entry is\n            # rejected. Non-scalar lists recurse into nested lists; other elements deserialize.\n            def read_list(field, raw, klass)\n              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","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/bidi/serialization/record.rb#L270-L306","documentation":"check_primitive validates that a BiDi field's value matches its declared primitive (string/boolean/number/integer). number accepts any Numeric; integer requires an Integer (rejecting e.g. 1.5). A value whose Ruby type does not match raises Error::SerializationError. Fields with no primitive descriptor are unchecked.","triggerScenarios":"Inbound BiDi payload carries a value of the wrong primitive type at a typed field — e.g. a string where integer is expected, or 1.5 where integer is expected, or a number where boolean is expected.","commonSituations":"Browser emits a value in an unexpected form, server bug, schema/client skew, a numeric field receiving a string from a non-conformant grid.","solutions":["Inspect the raw value to see the actual type that arrived.","Confirm the field's primitive in the W3C BiDi spec.","Align Selenium and browser/driver versions.","Report the non-conformant payload upstream."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"PRIM = { 'string' => String, 'boolean' => [TrueClass, FalseClass], 'integer' => Integer, 'number' => Numeric }.freeze\n\ndef expect_primitive!(value, prim, field)\n  types = Array(PRIM[prim])\n  raise \"#{field} expected #{prim}, got #{value.class}\" unless types.any? { |t| value.is_a?(t) }\n  value\nend","typeGuard":"def primitive_match?(value, prim)\n  Array({ 'string' => String, 'boolean' => [TrueClass, FalseClass], 'integer' => Integer, 'number' => Numeric }[prim]).any? { |t| value.is_a?(t) }\nend","tryCatchPattern":"begin\n  record = SomeRecord.from_json(payload)\nrescue Selenium::WebDriver::Error::SerializationError => e\n  raise unless e.message =~ /expected (string|boolean|number|integer)/\n  warn \"primitive mismatch: #{e.message}\"\nend","preventionTips":["Inspect raw payloads to see the actual Ruby type that arrived.","Keep client and browser versions aligned when primitive types evolve.","Report non-conformant primitives upstream with the payload."],"tags":["bidi","serialization","primitive","schema","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}