faker-ruby/faker · error · ArgumentError

Search terms must be specified for pixelated images

Error message

Search terms must be specified for pixelated images

What it means

Raised by Faker::LoremFlickr.pixelated_image when the search_terms array is empty. Like the grayscale variant, the LoremFlickr pixelated URL requires at least one search keyword segment, so `search_terms.any?` is enforced before build_url runs.

Source

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

      ##
      # Produces a random pixelated image URL from loremflickr.com.
      #
      # @param size [String] Specifies the size 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.pixelated_image #=> "https://loremflickr.com/p/300/300/all"
      #   Faker::LoremFlickr.pixelated_image(size: "50x60") #=> "https://loremflickr.com/p/50/60/all"
      #   Faker::LoremFlickr.pixelated_image(size: "50x60", search_terms: ['sports']) #=> "https://loremflickr.com/p/50/60/sports"
      #   Faker::LoremFlickr.pixelated_image(size: "50x60", search_terms: ['sports', 'fitness']) #=> "https://loremflickr.com/p/50/60/sports,fitness"
      #   Faker::LoremFlickr.pixelated_image(size: "50x60", search_terms: ['sports', 'fitness'], match_all: true) #=> "https://loremflickr.com/p/50/60/sports,fitness/all"
      #
      # @faker.version 1.9.0
      def pixelated_image(size: '300x300', search_terms: ['all'], match_all: false)
        raise ArgumentError, 'Search terms must be specified for pixelated images' unless search_terms.any?

        build_url(size, 'p', search_terms, match_all)
      end

      ##
      # 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"

View on GitHub (pinned to cca4184947)

Solutions

  1. Pass at least one term, e.g. search_terms: ['all'] or ['city'].
  2. Fallback when the source list is blank: `terms.empty? ? ['all'] : terms`.
  3. Validate in the calling layer that user-provided keyword lists are non-empty before reaching Faker.

Example fix

# before
Faker::LoremFlickr.pixelated_image(search_terms: query.split(',')) # query == ''

# after
terms = query.split(',')
terms = ['all'] if terms.empty?
Faker::LoremFlickr.pixelated_image(search_terms: terms)
Defensive patterns

Strategy: validation

Validate before calling

terms = query.to_s.split(',').map(&:strip).reject(&:empty?)
terms = ['all'] if terms.empty?
Faker::LoremFlickr.pixelated_image(search_terms: terms)

Type guard

def non_blank_terms?(terms)
  terms.is_a?(Array) && terms.compact.any? { |t| t.to_s.strip != '' }
end

Try / catch

begin
  Faker::LoremFlickr.pixelated_image(search_terms: terms)
rescue ArgumentError
  Faker::LoremFlickr.pixelated_image(search_terms: ['all'])
end

Prevention

When it happens

Trigger: Faker::LoremFlickr.pixelated_image(search_terms: []) — e.g. splitting an empty user query (`''.split(',')`) or filtering a tag list down to nothing before passing it.

Common situations: Controllers/helpers that pass `search_terms: params[:keywords].to_s.split(',')` and forget the blank case; view code that composes tags from optional filters; copy-pasting the grayscale example with dynamic terms.

Related errors


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