faker-ruby/faker · error · ArgumentError
Invalid credit cards argument can be left blank or include #
Error message
Invalid credit cards argument can be left blank or include #{invalid_cards.join(', ')} What it means
Raised by Faker::Stripe.invalid_card when card_error is not a key under faker.stripe.invalid_cards in the loaded locale (keys named after Stripe's decline error codes, e.g. :addressZipFail, :incorrectNumber...). The argument is symified then checked against the locale keys; note these keys are camelCase like Stripe's docs, so 'address_zip_fail' or :incorrect_number fail.
Source
Thrown at lib/faker/default/stripe.rb:75
##
# Produces a random invalid card number.
#
# @return [String]
#
# @example
# Faker::Stripe.invalid_card #=> "4000000000000002"
# Faker::Stripe.invalid_card(card_error: "addressZipFail") #=> "4000000000000010"
#
# @faker.version 1.9.0
def invalid_card(card_error: nil)
invalid_cards = translate('faker.stripe.invalid_cards').keys
if card_error.nil?
card_error = sample(invalid_cards).to_s
else
unless invalid_cards.include?(card_error.to_sym)
raise ArgumentError,
"Invalid credit cards argument can be left blank or include #{invalid_cards.join(', ')}"
end
end
fetch("stripe.invalid_cards.#{card_error}")
end
##
# Produces a random month in two digits format.
#
# @return [String]
#
# @example
# Faker::Stripe.month #=> "10"
#
# @faker.version 1.9.0
def month
format('%02d', rand_in_range(1, 12))View on GitHub (pinned to cca4184947)
Solutions
- Omit card_error to get a random invalid card number.
- Pass the exact camelCase key shown in the error message, e.g. card_error: 'addressZipFail' (string or symbol).
- For decline codes the gem does not ship, take the card number from the error's listed keys or hardcode the number from Stripe's testing docs.
Example fix
# before Faker::Stripe.invalid_card(card_error: :address_zip_fail) # ArgumentError # after Faker::Stripe.invalid_card(card_error: :addressZipFail)
Defensive patterns
Strategy: validation
Validate before calling
valid_errors = I18n.translate('faker.stripe.invalid_cards').keys.map(&:to_s)
card_error = nil unless card_error.nil? || valid_errors.include?(card_error.to_s)
Faker::Stripe.invalid_card(card_error: card_error) Type guard
def known_stripe_card_error?(card_error)
I18n.translate('faker.stripe.invalid_cards').key?(card_error.to_s.to_sym)
end Try / catch
begin Faker::Stripe.invalid_card(card_error: card_error) rescue ArgumentError Faker::Stripe.invalid_card # random decline end
Prevention
- Stripe decline keys are camelCase (addressZipFail), not snake_case.
- Check the locale section for available codes before looping over all Stripe declines.
- Omit card_error for a random invalid card.
When it happens
Trigger: Faker::Stripe.invalid_card(card_error: 'addressZipFail') works; card_error: 'address_zip_fail' (snake_case), card_error: 'rateLimit' (if absent from the locale) or any other unknown key raises at lib/faker/default/stripe.rb:75.
Common situations: Snake_casing Stripe's camelCase error names (a very common Ruby habit); using a decline code added in newer Stripe docs than the gem's locale data covers; tests iterating over all Stripe decline codes.
Related errors
- Valid credit cards argument can be left blank or include #{v
- Valid credit cards argument can be left blank or include #{v
- 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/56af4a6bf8bcdf7f.
Report an issue: GitHub.