faker-ruby/faker · error · ArgumentError
Filters do not match any sciences
Error message
Filters do not match any sciences
What it means
Raised by Faker::Science.science when the combination of branch filters produces an empty set of sciences. BRANCHES maps each filter (:empirical, :formal, :natural, :social, :basic, :applied) to a list of science categories, and the filters are intersected; contradictory pairs like :empirical + :formal (empirical covers empirical_* categories, formal covers formal_*) share no categories, so selected becomes empty and ArgumentError is raised. Unknown branch symbols are silently ignored (BRANCHES.key? guard), so they never trigger this error.
Source
Thrown at lib/faker/default/science.rb:37
# @see https://en.wikipedia.org/wiki/Science#Branches_of_science
# @see Faker::Educator.subject
#
# @param branches [Array<Symbol>]
# @return [String]
#
# @example
# Faker::Science.science #=> "Space science"
# Faker::Science.science(:natural, :applied) #=> "Engineering"
# Faker::Science.science(:formal, :applied) #=> "Computer Science"
#
# @faker.version next
def science(*branches)
selected = BRANCHES.values.flatten.uniq
branches.each do |branch|
selected &= BRANCHES[branch] if BRANCHES.key? branch
end
raise ArgumentError, 'Filters do not match any sciences' if selected.empty?
sciences = []
selected.each do |branch|
sciences += translate("faker.science.branch.#{branch}")
end
sample(sciences)
end
##
# Produces the name of a element.
#
# @return [String]
#
# @example
# Faker::Science.element #=> "Carbon"
#
# @faker.version 1.8.5View on GitHub (pinned to cca4184947)
Solutions
- Use compatible filter combinations: at most one branch-type (:empirical or :formal) combined with at most one modifier (:natural/:social and/or :basic/:applied), e.g. science(:natural, :applied).
- Call science with no arguments when you just want any science.
- Guard compound selections before calling by intersecting Faker::Science::BRANCHES values yourself and skipping empty results.
Example fix
# before Faker::Science.science(:empirical, :formal) # ArgumentError: contradictory filters # after Faker::Science.science(:formal, :applied) # 'Computer Science'
Defensive patterns
Strategy: validation
Validate before calling
BRANCHES = Faker::Science::BRANCHES
selected = BRANCHES.values.flatten.uniq
branches.each { |b| selected &= BRANCHES[b] if BRANCHES.key?(b) }
Faker::Science.science(*branches) unless selected.empty? Type guard
def compatible_science_filters?(branches)
b = Faker::Science::BRANCHES
selected = b.values.flatten.uniq
branches.each { |branch| selected &= b[branch] if b.key?(branch) }
!selected.empty?
end Try / catch
begin Faker::Science.science(*branches) rescue ArgumentError Faker::Science.science # unfiltered end
Prevention
- Never mix :empirical with :formal — they are disjoint branches.
- Keep filters to one from {empirical, formal} plus one from {natural, social} plus one from {basic, applied}.
- Misspelled filters are silently ignored; only contradictory valid ones raise, so log the filters you pass.
When it happens
Trigger: Faker::Science.science(:empirical, :formal) — the two filters intersect to an empty list and raise. Also :formal + :natural (natural only contains empirical_natural_* categories) raises. A single filter or none never raises.
Common situations: Building filter combinations programmatically from UI checkboxes and hitting mutually exclusive pairs; assuming any combination of valid filters is valid; not realizing misspelled filters (e.g. :nature) are ignored rather than validated, so the error only signals contradictory valid filters.
Related errors
- Supported colorizations are #{SUPPORTED_COLORIZATIONS.join('
- Supported formats are #{SUPPORTED_FORMATS.join(', ')}
- Familial connections can be left blank or #{familial_connect
- Valid credit cards argument can be left blank or include #{v
- Valid credit cards argument can be left blank or include #{v
AI-assisted analysis of faker-ruby/faker@cca4184947 (2026-08-21).
Data as JSON: /api/errors/c469629eab599465.
Report an issue: GitHub.