{"record":{"id":"989480bde06b5c6d","repo":"faker-ruby/faker","slug":"invalid-amount","errorCode":null,"errorMessage":"invalid amount","messagePattern":"invalid amount","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/faker/default/measurement.rb","lineNumber":156,"sourceCode":"        end\n      end\n\n      def define_measurement_locale(amount, locale)\n        ensure_valid_amount(amount)\n        case amount\n        when ALL\n          make_plural(fetch(\"measurement.#{locale}\"))\n        when NONE\n          fetch(\"measurement.#{locale}\")\n        else\n          locale = check_for_plural(fetch(\"measurement.#{locale}\"), amount)\n\n          \"#{amount} #{locale}\"\n        end\n      end\n\n      def ensure_valid_amount(amount)\n        raise ArgumentError, 'invalid amount' unless amount == NONE || amount == ALL || amount.is_a?(Integer) || amount.is_a?(Float)\n      end\n\n      def make_plural(text)\n        case text\n        when 'foot'\n          'feet'\n        when 'inch'\n          'inches'\n        when 'fluid ounce'\n          'fluid ounces'\n        when 'metric ton'\n          'metric tons'\n        else\n          \"#{text}s\"\n        end\n      end\n    end\n  end","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/faker-ruby/faker/blob/cca4184947e09fdd02afb8b89d25a9c8ebc7274e/lib/faker/default/measurement.rb#L138-L174","documentation":"Raised by the private ensure_valid_amount in Faker::Measurement (called by height, length, volume, weight, metric_height, metric_length, metric_volume, metric_weight via define_measurement_locale) when amount is anything other than the sentinels 'all'/'none' (NONE/ALL), an Integer, or a Float. Strings like '5', nil, or Decimals are rejected before the measurement string is built.","triggerScenarios":"Faker::Measurement.height(amount: '5') (numeric string), amount: nil, amount: BigDecimal('5'), or amount: [1, 2] raises 'invalid amount'; amount: 5, amount: 2.5, amount: 'all', amount: 'none' are accepted.","commonSituations":"Passing amounts parsed from params or config files where numbers arrive as strings ('amount=5' from a query string); BigDecimal from ActiveRecord aggregation; forgetting that the pluralization sentinels are the exact strings 'all'/'none', not symbols :all/:none.","solutions":["Pass an Integer or Float (5, 2.5) or the exact strings 'all'/'none'.","Convert numeric strings first: amount: params[:amount].to_i or .to_f.","If amount may legitimately be absent, omit the keyword (each method defaults to rand(10)) instead of passing nil."],"exampleFix":"# before\nFaker::Measurement.height(amount: params[:amount]) # '5' from query string -> ArgumentError\n\n# after\nFaker::Measurement.height(amount: params[:amount].to_i)","handlingStrategy":"validation","validationCode":"amount = Integer(amount) rescue Float(amount) rescue amount\nFaker::Measurement.height(amount: amount) if [Integer, Float].include?(amount.class) || %w[all none].include?(amount)","typeGuard":"def valid_measurement_amount?(amount)\n  amount.is_a?(Integer) || amount.is_a?(Float) || amount == 'all' || amount == 'none'\nend","tryCatchPattern":"begin\n  Faker::Measurement.height(amount: amount)\nrescue ArgumentError\n  Faker::Measurement.height # omit amount; method defaults to rand(10)\nend","preventionTips":["to_i/to_f numeric strings from params and config before passing.","Sentinels are the strings 'all'/'none', not symbols.","nil is invalid — omit the keyword instead of passing nil."],"tags":["faker","argument-error","type-validation","measurement"],"backgroundTag":"wrong-argument-type","analyzedSha":"cca4184947e09fdd02afb8b89d25a9c8ebc7274e","analyzedAt":"2026-08-21T16:25:39.145Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}