faker-ruby/faker · error · ArgumentError
Supported formats are #{SUPPORTED_FORMATS.join(', ')}
Error message
Supported formats are #{SUPPORTED_FORMATS.join(', ')} What it means
Raised by Faker::Placeholdit.image when format is not in SUPPORTED_FORMATS: 'png', 'jpg', 'gif', 'jpeg'. The whitelist is an exact string match, so 'PNG', :png, 'webp', 'svg', or 'jpg ' all fail and the message enumerates the four allowed values.
Source
Thrown at lib/faker/default/placeholdit.rb:34
# @return [String]
#
# @example
# # Keyword arguments: size, format, background_color, text_color, text
# Faker::Placeholdit.image #=> "https://via.placeholder.com/300x300.png"
# Faker::Placeholdit.image(size: '50x50') #=> "https://via.placeholder.com/50x50.png"
# Faker::Placeholdit.image(size: '50x50', format: 'jpg') #=> "https://via.placeholder.com/50x50.jpg"
# Faker::Placeholdit.image(size: '50x50', format: 'gif', background_color: 'ffffff') #=> "https://via.placeholder.com/50x50.gif/ffffff"
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: :random) #=> "https://via.placeholder.com/50x50.jpeg/39eba7"
# Faker::Placeholdit.image(size: '50x50', format: 'jpeg', background_color: 'ffffff', text_color: '000') #=> "https://via.placeholder.com/50x50.jpeg/ffffff/000"
# 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"
#
# @faker.version 1.6.0
def image(size: '300x300', format: 'png', background_color: nil, text_color: nil, text: nil)
background_color = generate_color if background_color == :random
text_color = generate_color if text_color == :random
raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /\A[0-9]+x[0-9]+\z$/
raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.nil? || background_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/
raise ArgumentError, "text_color must be a hex value without '#'" unless text_color.nil? || text_color =~ /((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/
image_url = "https://via.placeholder.com/#{size}.#{format}"
image_url += "/#{background_color}" if background_color
image_url += "/#{text_color}" if text_color
image_url += "?text=#{text}" if text
image_url
end
private
def generate_color
format('%06x', rand * 0xffffff)
end
end
end
endView on GitHub (pinned to cca4184947)
Solutions
- Use one of the exact lowercase strings: 'png', 'jpg', 'gif', 'jpeg'.
- Downcase and whitelist user input first: format = %w[png jpg gif jpeg].include?(f) ? f : 'png'.
- If you need another format, build the URL manually: "https://via.placeholder.com/50x50.#{format}".
Example fix
# before
Faker::Placeholdit.image(format: requested_format) # 'webp' -> ArgumentError
# after
Faker::Placeholdit.image(format: 'png')
# or bypass: "https://via.placeholder.com/300x300.#{requested_format}" Defensive patterns
Strategy: type-guard
Validate before calling
format = format.to_s.downcase format = 'png' unless Faker::Placeholdit::SUPPORTED_FORMATS.include?(format) Faker::Placeholdit.image(format: format)
Type guard
def supported_placeholdit_format?(format) Faker::Placeholdit::SUPPORTED_FORMATS.include?(format.to_s.downcase) end
Try / catch
begin Faker::Placeholdit.image(format: format) rescue ArgumentError Faker::Placeholdit.image # default png end
Prevention
- Check against the SUPPORTED_FORMATS constant rather than a hardcoded copy.
- Only lowercase strings count: :png and 'PNG' both fail.
- For formats the gem rejects, build the via.placeholder.com URL manually.
When it happens
Trigger: Faker::Placeholdit.image(format: 'webp'), format: 'PNG', or format: :png raises 'Supported formats are png, jpg, gif, jpeg'; format: 'png' (default) works.
Common situations: Forwarding a user-chosen or config-driven image format into the generator; assuming symbols are accepted like elsewhere in Faker; copy-pasting from placeholder services that support more formats (via.placeholder.com supports more than this gem whitelists).
Related errors
- Supported colorizations are #{SUPPORTED_COLORIZATIONS.join('
- 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
AI-assisted analysis of faker-ruby/faker@cca4184947 (2026-08-21).
Data as JSON: /api/errors/ffa1bd9dc48c5813.
Report an issue: GitHub.