{"record":{"id":"5295beeacea86cff","repo":"faker-ruby/faker","slug":"valid-credit-cards-argument-can-be-left-blank-or-i-5295be","errorCode":null,"errorMessage":"Valid credit cards argument can be left blank or include #{valid_tokens.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":50,"sourceCode":"      ##\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\n      def valid_token(card_type: nil)\n        valid_tokens = translate('faker.stripe.valid_tokens').keys\n\n        if card_type.nil?\n          card_type = sample(valid_tokens).to_s\n        else\n          unless valid_tokens.include?(card_type.to_sym)\n            raise ArgumentError,\n                  \"Valid credit cards argument can be left blank or include #{valid_tokens.join(', ')}\"\n          end\n        end\n\n        fetch(\"stripe.valid_tokens.#{card_type}\")\n      end\n\n      ##\n      # Produces a random invalid card number.\n      #\n      # @return [String]\n      #\n      # @example\n      #   Faker::Stripe.invalid_card #=> \"4000000000000002\"\n      #   Faker::Stripe.invalid_card(card_error: \"addressZipFail\") #=> \"4000000000000010\"\n      #\n      # @faker.version 1.9.0\n      def invalid_card(card_error: nil)","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/faker-ruby/faker/blob/cca4184947e09fdd02afb8b89d25a9c8ebc7274e/lib/faker/default/stripe.rb#L32-L68","documentation":"Raised by Faker::Stripe.valid_token when card_type is not a key under faker.stripe.valid_tokens in the loaded locale (e.g. :visa, :mastercard, :amex...). Like valid_card, the argument is symified before comparison, so 'visa' and :visa both pass while anything absent from the locale section (e.g. 'visa_debit' in locales that lack that token key) raises.","triggerScenarios":"Faker::Stripe.valid_token(card_type: 'discover') when discover is not defined under stripe.valid_tokens raises; valid_token() with no argument samples randomly and never raises.","commonSituations":"Assuming the token keys mirror the card keys exactly (valid_cards and valid_tokens sections can differ); sharing one card-type constant list between valid_card and valid_token calls; locale data differences across faker versions.","solutions":["Omit card_type to get a random valid token.","Use a type listed in the error message (string or lowercase symbol), e.g. card_type: 'mc_debit'.","Derive the accepted set at runtime from the locale (I18n translate keys under faker.stripe.valid_tokens) instead of hardcoding."],"exampleFix":"# before\nFaker::Stripe.valid_token(card_type: 'discover') # ArgumentError\n\n# after\nFaker::Stripe.valid_token(card_type: 'mc_debit')\n# or: Faker::Stripe.valid_token","handlingStrategy":"validation","validationCode":"valid_types = I18n.translate('faker.stripe.valid_tokens').keys.map(&:to_s)\ncard_type = nil unless card_type.nil? || valid_types.include?(card_type.to_s)\nFaker::Stripe.valid_token(card_type: card_type)","typeGuard":"def known_stripe_token_type?(card_type)\n  I18n.translate('faker.stripe.valid_tokens').key?(card_type.to_s.to_sym)\nend","tryCatchPattern":"begin\n  Faker::Stripe.valid_token(card_type: card_type)\nrescue ArgumentError\n  Faker::Stripe.valid_token # random token\nend","preventionTips":["Do not reuse a valid_cards key list for valid_token — the sections differ.","Read accepted keys from the locale at runtime to survive gem upgrades.","Omit card_type when any token will do."],"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"}