{"record":{"id":"dd0fc4b793c8c9f9","repo":"faker-ruby/faker","slug":"text-color-must-be-a-hex-value-without","errorCode":null,"errorMessage":"text_color must be a hex value without '#'","messagePattern":"text_color must be a hex value without '#'","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/faker/default/placeholdit.rb","lineNumber":36,"sourceCode":"      # @example\n      #     # Keyword arguments: size, format, background_color, text_color, text\n      #   Faker::Placeholdit.image #=> \"https://via.placeholder.com/300x300.png\"\n      #   Faker::Placeholdit.image(size: '50x50') #=> \"https://via.placeholder.com/50x50.png\"\n      #   Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> \"https://via.placeholder.com/50x50.jpg\"\n      #   Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> \"https://via.placeholder.com/50x50.gif/ffffff\"\n      #   Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> \"https://via.placeholder.com/50x50.jpeg/39eba7\"\n      #   Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> \"https://via.placeholder.com/50x50.jpeg/ffffff/000\"\n      #   Faker::Placeholdit.image(size: '50x50', format: 'jpg', background_color: 'ffffff', text_color: '000', text: 'Some Custom Text') #=> \"https://via.placeholder.com/50x50.jpg/ffffff/000?text=Some Custom Text\"\n      #\n      # @faker.version 1.6.0\n      def image(size: '300x300', format: 'png', background_color: nil, text_color: nil, text: nil)\n        background_color = generate_color if background_color == :random\n        text_color = generate_color if text_color == :random\n\n        raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /\\A[0-9]+x[0-9]+\\z$/\n        raise ArgumentError, \"Supported formats are #{SUPPORTED_FORMATS.join(', ')}\" unless SUPPORTED_FORMATS.include?(format)\n        raise ArgumentError, \"background_color must be a hex value without '#'\" unless background_color.nil? || background_color =~ /((?:^\\h{3}$)|(?:^\\h{6}$)){1}(?!.*\\H)/\n        raise ArgumentError, \"text_color must be a hex value without '#'\" unless text_color.nil? || text_color =~ /((?:^\\h{3}$)|(?:^\\h{6}$)){1}(?!.*\\H)/\n\n        image_url = \"https://via.placeholder.com/#{size}.#{format}\"\n        image_url += \"/#{background_color}\" if background_color\n        image_url += \"/#{text_color}\" if text_color\n        image_url += \"?text=#{text}\" if text\n        image_url\n      end\n\n      private\n\n      def generate_color\n        format('%06x', rand * 0xffffff)\n      end\n    end\n  end\nend\n","sourceCodeStart":18,"sourceCodeEnd":53,"githubUrl":"https://github.com/faker-ruby/faker/blob/cca4184947e09fdd02afb8b89d25a9c8ebc7274e/lib/faker/default/placeholdit.rb#L18-L53","documentation":"Raised by Faker::Placeholdit.image when text_color is given and does not match the bare-hex shapes 'hhh' or 'hhhhhh'. Identical validation to background_color: a leading '#', 4/5-digit hex, or color names like 'black' are rejected; :random is replaced with a generated color before the guard runs.","triggerScenarios":"Faker::Placeholdit.image(text_color: '#000') (hash included), text_color: 'black', or text_color: '0000' raises 'text_color must be a hex value without \\'#\\''; text_color: '000' is accepted.","commonSituations":"Pairing the text color with a background color in a view helper and forgetting both must be hash-less; forwarding design-token colors that use '#rgb' notation; alpha-padded hex from design tools.","solutions":["Pass 3- or 6-digit hex without '#': text_color: '000' or '000000'.","Normalize design tokens: text_color: token.delete('#').","Use text_color: :random when the exact tint does not matter."],"exampleFix":"# before\nFaker::Placeholdit.image(background_color: 'ffffff', text_color: '#000000') # ArgumentError\n\n# after\nFaker::Placeholdit.image(background_color: 'ffffff', text_color: '000000')","handlingStrategy":"validation","validationCode":"text_color = text_color.to_s.delete('#').downcase\ntext_color = nil unless text_color.match?(/\\A(?:\\h{3}|\\h{6})\\z/)\nFaker::Placeholdit.image(background_color: 'ffffff', text_color: text_color)","typeGuard":"def bare_hex_color?(value)\n  value.is_a?(String) && value.match?(/\\A(?:\\h{3}|\\h{6})\\z/)\nend","tryCatchPattern":"begin\n  Faker::Placeholdit.image(text_color: fg)\nrescue ArgumentError\n  Faker::Placeholdit.image(text_color: :random)\nend","preventionTips":["Apply the same hash-stripping normalization to both background_color and text_color.","Design tools export '#rgb'/'#rrggbb' and 8-digit alpha hex — normalize both away.","Prefer :random over hand-typed hex in throwaway fixtures."],"tags":["faker","argument-error","format-validation","image-url","hex-color","placeholdit"],"backgroundTag":"invalid-hex-color","analyzedSha":"cca4184947e09fdd02afb8b89d25a9c8ebc7274e","analyzedAt":"2026-08-21T16:25:39.145Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}