{"record":{"id":"cde7b4971e81a747","repo":"SeleniumHQ/selenium","slug":"custom-page-size-must-include-width-and-height","errorCode":null,"errorMessage":"Custom page size must include :width and :height","messagePattern":"Custom page size must include :width and :height","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/print_options.rb","lineNumber":83,"sourceCode":"      # Sets the page size. Can be a predefined symbol or custom size hash.\n      #\n      # @param [Symbol, Hash] value The predefined size (:letter, :legal, :a4, :tabloid) or a custom hash.\n      def page_size=(value)\n        predefined_sizes = {\n          letter: {width: 21.59, height: 27.94},\n          legal: {width: 21.59, height: 35.56},\n          a4: {width: 21.0, height: 29.7},\n          tabloid: {width: 27.94, height: 43.18}\n        }\n\n        case value\n        when Symbol\n          raise ArgumentError, \"Invalid page size: #{value}\" unless predefined_sizes.key?(value)\n\n          @page_size = predefined_sizes[value]\n        when Hash\n          unless value.key?(:width) && value.key?(:height)\n            raise ArgumentError, 'Custom page size must include :width and :height'\n          end\n\n          @page_size = value\n        else\n          raise ArgumentError, 'Page size must be a Symbol or a Hash'\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":65,"sourceCodeEnd":94,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/print_options.rb#L65-L94","documentation":"When page_size= is given a Hash, it must contain both :width and :height keys (Symbol keys). If either is missing, ArgumentError is raised. The values represent dimensions in centimeters.","triggerScenarios":"Passing { width: 21.0 } without :height. Using string keys 'width'/'height' instead of Symbols. Passing an incomplete hash built from partial user input.","commonSituations":"Constructing the hash programmatically and omitting one dimension. Using string keys because the data came from JSON. Copying a partial config.","solutions":["Include both Symbol keys: page_size = { width: 21.0, height: 29.7 }.","If keys come from JSON/string sources, transform them: hash.transform_keys(&:to_sym).","Validate value.key?(:width) && value.key?(:height) before assignment."],"exampleFix":"# before\nprint_options.page_size = { 'width' => 21.0 }\n\n# after\nprint_options.page_size = { width: 21.0, height: 29.7 }","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'page size needs :width and :height' unless hash.key?(:width) && hash.key?(:height)","typeGuard":"def complete_page_hash?(hash)\n  hash.is_a?(Hash) && hash.key?(:width) && hash.key?(:height)\nend","tryCatchPattern":"begin\n  print_options.page_size = hash\nrescue ArgumentError => e\n  raise unless e.message.include?('width and :height')\n  print_options.page_size = hash.transform_keys(&:to_sym)\nend","preventionTips":["Use Symbol keys (:width, :height) when building custom sizes.","transform_keys(&:to_sym) when data originates from JSON/string sources.","Validate both keys exist before assignment."],"tags":["ruby","print","page-size","validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}