faker-ruby/faker · error · ArgumentError
state code must be in a range of 02 to 38 or 98
Error message
state code must be in a range of 02 to 38 or 98
What it means
Error "state code must be in a range of 02 to 38 or 98" thrown in faker-ruby/faker.
Source
Thrown at lib/faker/default/company.rb:483
end
##
# Get a random Indian Goods and Services Tax (GST) number.
# For more on Indian tax number here:
# https://simple.wikipedia.org/wiki/GSTIN
# @params state code [String] Any state code.
#
# @return [String]
# @example
# Faker::Company.indian_gst_number #=> "15VQPNZ2126J2ZU"
# Faker::Company.indian_gst_number(state_code: "22") #=> "22ZVWEY6632K0ZN"
#
# @faker.version 3.2.1
def indian_gst_number(state_code: nil)
# Check if state code is valid
state_code_ranges = [('02'..'38'), ['98']]
if state_code && !(state_code_ranges[0].include?(state_code) || state_code == '98')
raise ArgumentError, 'state code must be in a range of 02 to 38 or 98'
end
PositionalGenerator.new(:string) do |gen|
# Generate a state code if not given
if state_code
gen.lit(state_code, name: :state_code_param)
else
gen.letter(name: :state_code_param, length: 1, ranges: state_code_ranges)
end
# Construct taxpayer number
gen.group(name: :taxpayer_number) do |g_|
g_.letter(length: 3, ranges: ['A'..'Z'])
g_.letter(length: 1, ranges: [%w[A B C F G H L J P T K]])
g_.letter(length: 1, ranges: ['A'..'Z'])
g_.int(length: 4, ranges: [0..9999])
g_.letter(length: 1, ranges: ['A'..'Z'])
endView on GitHub (pinned to cca4184947)
When it happens
Trigger: Thrown at lib/faker/default/company.rb:483 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of faker-ruby/faker@cca4184947 (2026-08-21).
Data as JSON: /api/errors/2d044a3503bc2217.
Report an issue: GitHub.