{"record":{"id":"643e2fba8343ca8c","repo":"faker-ruby/faker","slug":"valid-credit-cards-argument-can-be-left-blank-or-i","errorCode":null,"errorMessage":"Valid credit cards argument can be left blank or include #{valid_cards.join(', ')}","messagePattern":"Valid credit cards argument can be left blank or include #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/faker/default/stripe.rb","lineNumber":24,"sourceCode":"      ##\n      # Produces a random valid card number.\n      #\n      # @param card_type [String] Specific valid card type.\n      # @return [String]\n      #\n      # @example\n      #   Faker::Stripe.valid_card #=> \"4242424242424242\"\n      #   Faker::Stripe.valid_card(card_type: \"visa_debit\") #=> \"4000056655665556\"\n      #\n      # @faker.version 1.9.0\n      def valid_card(card_type: nil)\n        valid_cards = translate('faker.stripe.valid_cards').keys\n\n        if card_type.nil?\n          card_type = sample(valid_cards).to_s\n        else\n          unless valid_cards.include?(card_type.to_sym)\n            raise ArgumentError,\n                  \"Valid credit cards argument can be left blank or include #{valid_cards.join(', ')}\"\n          end\n        end\n\n        fetch(\"stripe.valid_cards.#{card_type}\")\n      end\n\n      ##\n      # Produces a random valid Stripe token.\n      #\n      # @param card_type [String] Specific valid card type.\n      # @return [String]\n      #\n      # @example\n      #   Faker::Stripe.valid_token #=> \"tok_visa\"\n      #   Faker::Stripe.valid_token(card_type: \"mc_debit\") #=> \"tok_mastercard_debit\"\n      #\n      # @faker.version 1.9.0","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/faker-ruby/faker/blob/cca4184947e09fdd02afb8b89d25a9c8ebc7274e/lib/faker/default/stripe.rb#L6-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nFaker::Stripe.valid_card(card_type: 'visa_credit') # ArgumentError\n\n# after\nFaker::Stripe.valid_card(card_type: 'visa_debit')\n# or: Faker::Stripe.valid_card","handlingStrategy":"validation","validationCode":"valid_types = I18n.translate('faker.stripe.valid_cards').keys.map(&:to_s)\ncard_type = nil unless card_type.nil? || valid_types.include?(card_type.to_s)\nFaker::Stripe.valid_card(card_type: card_type)","typeGuard":"def known_stripe_card_type?(card_type)\n  I18n.translate('faker.stripe.valid_cards').key?(card_type.to_s.to_sym)\nend","tryCatchPattern":"begin\n  Faker::Stripe.valid_card(card_type: card_type)\nrescue ArgumentError\n  Faker::Stripe.valid_card # random card type\nend","preventionTips":["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."],"tags":["faker","argument-error","enum-whitelist","stripe","payment-testing"],"backgroundTag":"invalid-enum-argument","analyzedSha":"cca4184947e09fdd02afb8b89d25a9c8ebc7274e","analyzedAt":"2026-08-21T16:25:39.145Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}