faker-ruby/faker · error · ArgumentError
Size should be specified in format 300x300
Error message
Size should be specified in format 300x300
What it means
Raised by the private Faker::LoremFlickr.build_url (used by image, grayscale_image, pixelated_image, colorized_image) when the size string does not match /\A[0-9]+x[0-9]+\z/ — i.e. anything other than digits, a literal 'x', digits. The URL path needs the width and height as separate segments, so malformed sizes like '300', '300x', '300X300', '300 x 300', or '300.5x200' are rejected.
Source
Thrown at lib/faker/default/lorem_flickr.rb:99
# @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
end
View on GitHub (pinned to cca4184947)
Solutions
- Pass size as digits-x-digits, e.g. size: '300x300' or size: "#{width}x#{height}".
- Normalize before calling: size = "#{width.to_i}x#{height.to_i}" to strip whitespace/nil.
- Validate with the same regex in the calling layer: size =~ /\A[0-9]+x[0-9]+\z/.
Example fix
# before
Faker::LoremFlickr.image(size: "#{width} x #{height}") # ArgumentError
# after
Faker::LoremFlickr.image(size: "#{width.to_i}x#{height.to_i}") Defensive patterns
Strategy: validation
Validate before calling
size = "#{width.to_i}x#{height.to_i}"
raise ArgumentError, 'bad size' unless size =~ /\A[0-9]+x[0-9]+\z/
Faker::LoremFlickr.image(size: size, search_terms: terms) Type guard
def valid_loremflickr_size?(size) size.is_a?(String) && size.match?(/\A[0-9]+x[0-9]+\z/) end
Try / catch
begin Faker::LoremFlickr.image(size: size) rescue ArgumentError Faker::LoremFlickr.image # default 300x300 end
Prevention
- Always interpolate dimensions with to_i so nil never reaches the string.
- Use ASCII lowercase 'x', never 'X' or Unicode multiplication signs.
- Keep one size-formatting helper for all placeholder image gems you use.
When it happens
Trigger: Faker::LoremFlickr.image(size: '300') or size: '100*100', size: '50X60' (capital X), size: '50x60 ' (trailing space) raises 'Size should be specified in format 300x300'.
Common situations: Composing size from variables: "#{w}x#{h}" when one side is nil gives '300x'; accepting dimensions from user input or config without normalization; using '×' (Unicode multiplication sign) instead of ASCII 'x'.
Related errors
- Size should be specified in format 300x300
- background_color must be a hex value without '#'
- text_color must be a hex value without '#'
- Search terms must be specified for grayscale images
- Search terms must be specified for pixelated images
AI-assisted analysis of faker-ruby/faker@cca4184947 (2026-08-21).
Data as JSON: /api/errors/f6527ef4a327a78d.
Report an issue: GitHub.