{"record":{"id":"36d103b2f7625452","repo":"SeleniumHQ/selenium","slug":"name-field-name-expected-array-field-scala","errorCode":null,"errorMessage":"#{name}##{field.name} expected #{Array(field.scalar).join(' or ')}, got #{value.inspect}","messagePattern":"#(.+?)##(.+?) expected #(.+?), got #(.+?)","errorType":"exception","errorClass":"Error::SerializationError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/bidi/serialization/record.rb","lineNumber":335,"sourceCode":"                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,\n                    \"#{name}##{field.name} expected #{Array(field.scalar).join(' or ')}, got #{value.inspect}\"\n            end\n\n            def extra(json_payload)\n              known = (@wire_keys ||= fields.map(&:wire_key))\n              json_payload.except(*known)\n            end\n\n            # Forward-compat signal: a property a closed type does not model is dropped and warned so\n            # schema drift is visible (an extensible type keeps its extras silently — the spec sanctions\n            # them). Tagged +:bidi_undeclared_property+ so a caller can silence it via +logger.ignore+.\n            def warn_undeclared(undeclared)\n              undeclared.each_key do |key|\n                WebDriver.logger.warn(\"#{name} received an undeclared property: #{key.inspect}\",\n                                      id: :bidi_undeclared_property)\n              end\n            end\n          end","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/bidi/serialization/record.rb#L317-L353","documentation":"scalar_value validates a bare scalar at a scalar-tolerant union position (e.g. input.Origin's 'viewport'/'pointer' literals). The scalar must match one of the union's scalar-arm primitives; a wrong-typed scalar (number where string expected) raises Error::SerializationError. An unrecognized primitive name is left unchecked (lenient default).","triggerScenarios":"Inbound or outbound scalar at a union position whose type does not match any scalar arm — e.g. passing 123 to a union whose scalar arms are string literals, or 'x' where a number is expected.","commonSituations":"Caller passes the wrong literal/type to a BiDi input command (origin, button enums), schema/client skew on union scalar arms.","solutions":["Pass one of the documented scalar literals for the union (e.g. :viewport / :pointer for input Origin).","Check the field's scalar arms in the generated schema and use a matching value.","Align Selenium and browser versions if the arms changed."],"exampleFix":"// before\nactions.move(origin: 123, x: 0, y: 0)\n// after\nactions.move(origin: :viewport, x: 0, y: 0)","handlingStrategy":"type-guard","validationCode":"ALLOWED_ORIGINS = %w[viewport pointer].freeze\n\ndef valid_origin?(o)\n  ALLOWED_ORIGINS.include?(o.to_s)\nend","typeGuard":"def valid_union_scalar?(value, allowed)\n  Array(allowed).include?(value.to_s) || Array(allowed).include?(value)\nend","tryCatchPattern":"begin\n  actions.move(origin: origin_value, x: 0, y: 0)\nrescue Selenium::WebDriver::Error::SerializationError => e\n  raise unless e.message =~ /expected .* or .*, got/\n  warn \"bad union scalar: #{e.message}\"\nend","preventionTips":["Pass only documented scalar literals for union positions (e.g. :viewport/:pointer for Origin).","Centralize allowed enum/scalar literals in a constant and validate against it.","Unit-test BiDi input commands with each documented scalar arm."],"tags":["bidi","serialization","union","scalar","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}