faker-ruby/faker · error · ArgumentError
Valid credit cards argument can be left blank or include #{v
Error message
Valid credit cards argument can be left blank or include #{valid_cards.join(', ')} What it means
Raised by Faker::Stripe.valid_card when card_type is not a key under faker.stripe.valid_cards in the loaded locale (e.g. :visa, :visa_debit, :mastercard, :mc_debit, :amex... depending on locale data). The value is symified before the check, so both 'visa' and :visa work, but unknown strings like 'visa_credit' raise ArgumentError listing the accepted card types.
Source
Thrown at lib/faker/default/stripe.rb:24
##
# Produces a random valid card number.
#
# @param card_type [String] Specific valid card type.
# @return [String]
#
# @example
# Faker::Stripe.valid_card #=> "4242424242424242"
# Faker::Stripe.valid_card(card_type: "visa_debit") #=> "4000056655665556"
#
# @faker.version 1.9.0
def valid_card(card_type: nil)
valid_cards = translate('faker.stripe.valid_cards').keys
if card_type.nil?
card_type = sample(valid_cards).to_s
else
unless valid_cards.include?(card_type.to_sym)
raise ArgumentError,
"Valid credit cards argument can be left blank or include #{valid_cards.join(', ')}"
end
end
fetch("stripe.valid_cards.#{card_type}")
end
##
# Produces a random valid Stripe token.
#
# @param card_type [String] Specific valid card type.
# @return [String]
#
# @example
# Faker::Stripe.valid_token #=> "tok_visa"
# Faker::Stripe.valid_token(card_type: "mc_debit") #=> "tok_mastercard_debit"
#
# @faker.version 1.9.0View on GitHub (pinned to cca4184947)
Solutions
- Omit card_type to get a random valid card.
- Use one of the types listed in the error message, e.g. card_type: 'visa_debit' (string or symbol, lowercase).
- Check the accepted keys from your locale file (en.yml under stripe: valid_cards:) or rescue ArgumentError and sample the keys via I18n to stay robust across versions.
Example fix
# before Faker::Stripe.valid_card(card_type: 'visa_credit') # ArgumentError # after Faker::Stripe.valid_card(card_type: 'visa_debit') # or: Faker::Stripe.valid_card
Defensive patterns
Strategy: validation
Validate before calling
valid_types = I18n.translate('faker.stripe.valid_cards').keys.map(&:to_s)
card_type = nil unless card_type.nil? || valid_types.include?(card_type.to_s)
Faker::Stripe.valid_card(card_type: card_type) Type guard
def known_stripe_card_type?(card_type)
I18n.translate('faker.stripe.valid_cards').key?(card_type.to_s.to_sym)
end Try / catch
begin Faker::Stripe.valid_card(card_type: card_type) rescue ArgumentError Faker::Stripe.valid_card # random card type end
Prevention
- Derive accepted card types from the locale keys instead of Stripe docs.
- card_type keys can differ between valid_cards, valid_tokens, and invalid_cards sections.
- Strings and symbols both work; casing must match the locale key.
When it happens
Trigger: Faker::Stripe.valid_card(card_type: 'visa_credit') or any key not present in the en.yml stripe.valid_cards section raises; valid_card() with no argument samples a random type and never raises.
Common situations: Hardcoding card names from Stripe's documentation that differ from the gem's locale keys (e.g. 'visa' vs 'visa_credit'); locale files that define fewer valid_cards keys than expected; tests looping over a card list copied from another gem version.
Related errors
- Valid credit cards argument can be left blank or include #{v
- Invalid credit cards argument can be left blank or include #
- Supported colorizations are #{SUPPORTED_COLORIZATIONS.join('
- Supported formats are #{SUPPORTED_FORMATS.join(', ')}
- Familial connections can be left blank or #{familial_connect
AI-assisted analysis of faker-ruby/faker@cca4184947 (2026-08-21).
Data as JSON: /api/errors/643e2fba8343ca8c.
Report an issue: GitHub.