{"record":{"id":"c469629eab599465","repo":"faker-ruby/faker","slug":"filters-do-not-match-any-sciences","errorCode":null,"errorMessage":"Filters do not match any sciences","messagePattern":"Filters do not match any sciences","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/faker/default/science.rb","lineNumber":37,"sourceCode":"      # @see https://en.wikipedia.org/wiki/Science#Branches_of_science\n      # @see Faker::Educator.subject\n      #\n      # @param branches [Array<Symbol>]\n      # @return [String]\n      #\n      # @example\n      #   Faker::Science.science #=> \"Space science\"\n      #   Faker::Science.science(:natural, :applied) #=> \"Engineering\"\n      #   Faker::Science.science(:formal, :applied) #=> \"Computer Science\"\n      #\n      # @faker.version next\n      def science(*branches)\n        selected = BRANCHES.values.flatten.uniq\n        branches.each do |branch|\n          selected &= BRANCHES[branch] if BRANCHES.key? branch\n        end\n\n        raise ArgumentError, 'Filters do not match any sciences' if selected.empty?\n\n        sciences = []\n        selected.each do |branch|\n          sciences += translate(\"faker.science.branch.#{branch}\")\n        end\n\n        sample(sciences)\n      end\n\n      ##\n      # Produces the name of a element.\n      #\n      # @return [String]\n      #\n      # @example\n      #   Faker::Science.element #=> \"Carbon\"\n      #\n      # @faker.version 1.8.5","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/faker-ruby/faker/blob/cca4184947e09fdd02afb8b89d25a9c8ebc7274e/lib/faker/default/science.rb#L19-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nFaker::Science.science(:empirical, :formal) # ArgumentError: contradictory filters\n\n# after\nFaker::Science.science(:formal, :applied) # 'Computer Science'","handlingStrategy":"validation","validationCode":"BRANCHES = Faker::Science::BRANCHES\nselected = BRANCHES.values.flatten.uniq\nbranches.each { |b| selected &= BRANCHES[b] if BRANCHES.key?(b) }\nFaker::Science.science(*branches) unless selected.empty?","typeGuard":"def compatible_science_filters?(branches)\n  b = Faker::Science::BRANCHES\n  selected = b.values.flatten.uniq\n  branches.each { |branch| selected &= b[branch] if b.key?(branch) }\n  !selected.empty?\nend","tryCatchPattern":"begin\n  Faker::Science.science(*branches)\nrescue ArgumentError\n  Faker::Science.science # unfiltered\nend","preventionTips":["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."],"tags":["faker","argument-error","enum-whitelist","combination-validation","science"],"backgroundTag":"contradictory-filter-combination","analyzedSha":"cca4184947e09fdd02afb8b89d25a9c8ebc7274e","analyzedAt":"2026-08-21T16:25:39.145Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}