faker-ruby/faker · error · ArgumentError

Supported colorizations are #{SUPPORTED_COLORIZATIONS.join('

Error message

Supported colorizations are #{SUPPORTED_COLORIZATIONS.join(', ')}

What it means

Raised by Faker::LoremFlickr.colorized_image when color is not one of the SUPPORTED_COLORIZATIONS: 'red', 'green', 'blue'. The check is an exact include? on the frozen whitelist, so case and type matter — :red works only as the string 'red'; 'Red', 'red '.strip issues, or symbols like :blue raise.

Source

Thrown at lib/faker/default/lorem_flickr.rb:91

      # Produces a random colorized image URL from loremflickr.com.
      #
      # @param size [String] Specifies the size of image to generate.
      # @param color [String] Specifies the color of image to generate.
      # @param search_terms [Array<String>] Adds search terms to the image URL.
      # @param match_all [Boolean] Add "all" as part of the URL.
      # @return [String]
      #
      # @example
      #   Faker::LoremFlickr.image #=> "https://loremflickr.com/red/300/300/all"
      #   Faker::LoremFlickr.image(size: "50x60", color: 'blue') #=> "https://loremflickr.com/blue/50/60/all"
      #   Faker::LoremFlickr.image(size: "50x60", color: 'blue', search_terms: ['sports']) #=> "https://loremflickr.com/blue/50/60/sports"
      #   Faker::LoremFlickr.image(size: "50x60", color: 'blue', search_terms: ['sports', 'fitness']) #=> "https://loremflickr.com/blue/50/60/sports,fitness"
      #   Faker::LoremFlickr.image(size: "50x60", color: 'blue', search_terms: ['sports', 'fitness'], match_all: true) #=> "https://loremflickr.com/blue/50/60/sports,fitness/all"
      #
      # @faker.version 1.9.0
      def colorized_image(size: '300x300', color: 'red', search_terms: ['all'], match_all: false)
        raise ArgumentError, 'Search terms must be specified for colorized images' unless search_terms.any?
        raise ArgumentError, "Supported colorizations are #{SUPPORTED_COLORIZATIONS.join(', ')}" unless SUPPORTED_COLORIZATIONS.include?(color)

        build_url(size, color, search_terms, match_all)
      end

      private

      def build_url(size, format, search_terms, match_all)
        raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /\A[0-9]+x[0-9]+\z/

        url_parts = ['https://loremflickr.com']
        url_parts << format
        url_parts += size.split('x')
        url_parts << search_terms.compact.join(',') if search_terms.any?
        url_parts << 'all' if match_all
        url_parts.compact.join('/')
      end
    end
  end

View on GitHub (pinned to cca4184947)

Solutions

  1. Use exactly 'red', 'green', or 'blue' (lowercase strings) for color.
  2. Downcase and validate user/theme input against Faker::LoremFlickr::SUPPORTED_COLORIZATIONS before calling.
  3. If the desired tint is unsupported, use Faker::LoremFlickr.image without a color instead.

Example fix

# before
Faker::LoremFlickr.colorized_image(color: 'Red', search_terms: ['cats']) # ArgumentError

# after
Faker::LoremFlickr.colorized_image(color: 'red', search_terms: ['cats'])
Defensive patterns

Strategy: type-guard

Validate before calling

color = color.to_s.downcase
color = 'red' unless Faker::LoremFlickr::SUPPORTED_COLORIZATIONS.include?(color)
Faker::LoremFlickr.colorized_image(color: color, search_terms: terms)

Type guard

def supported_colorization?(color)
  Faker::LoremFlickr::SUPPORTED_COLORIZATIONS.include?(color.to_s.downcase)
end

Try / catch

begin
  Faker::LoremFlickr.colorized_image(color: color, search_terms: terms)
rescue ArgumentError
  Faker::LoremFlickr.colorized_image(color: 'red', search_terms: terms)
end

Prevention

When it happens

Trigger: Faker::LoremFlickr.colorized_image(color: 'red', search_terms: ['cats']) is fine; color: 'purple', 'Red', or :green raises at lib/faker/default/lorem_flickr.rb:91 with the message listing 'red, green, blue'.

Common situations: Passing arbitrary CSS color names from a UI theme picker into Faker; assuming symbols work because other Faker generators accept symbols; copying the whitelist from a newer/older faker version where the set differs.

Related errors


AI-assisted analysis of faker-ruby/faker@cca4184947 (2026-08-21). Data as JSON: /api/errors/3bcfcad496e6dd8b. Report an issue: GitHub.