{"record":{"id":"da518889d27e13e3","repo":"faker-ruby/faker","slug":"search-terms-must-be-specified-for-grayscale-image","errorCode":null,"errorMessage":"Search terms must be specified for grayscale images","messagePattern":"Search terms must be specified for grayscale images","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/faker/default/lorem_flickr.rb","lineNumber":45,"sourceCode":"\n      ##\n      # Produces a random grayscale image URL from loremflickr.com.\n      #\n      # @param size [String] Specifies the size of image to generate.\n      # @param search_terms [Array<String>] Adds search terms to the image URL.\n      # @param match_all [Boolean] Add \"all\" as part of the URL.\n      # @return [String]\n      #\n      # @example\n      #   Faker::LoremFlickr.grayscale_image #=> \"https://loremflickr.com/g/300/300/all\"\n      #   Faker::LoremFlickr.grayscale_image(size: \"50x60\") #=> \"https://loremflickr.com/g/50/60/all\"\n      #   Faker::LoremFlickr.grayscale_image(size: \"50x60\", search_terms: ['sports']) #=> \"https://loremflickr.com/g/50/60/sports\"\n      #   Faker::LoremFlickr.grayscale_image(size: \"50x60\", search_terms: ['sports', 'fitness']) #=> \"https://loremflickr.com/50/60/g/sports,fitness\"\n      #   Faker::LoremFlickr.grayscale_image(size: \"50x60\", search_terms: ['sports', 'fitness'], match_all: true) #=> \"https://loremflickr.com/g/50/60/sports,fitness/all\"\n      #\n      # @faker.version 1.9.0\n      def grayscale_image(size: '300x300', search_terms: ['all'], match_all: false)\n        raise ArgumentError, 'Search terms must be specified for grayscale images' unless search_terms.any?\n\n        build_url(size, 'g', search_terms, match_all)\n      end\n\n      ##\n      # Produces a random pixelated image URL from loremflickr.com.\n      #\n      # @param size [String] Specifies the size of image to generate.\n      # @param search_terms [Array<String>] Adds search terms to the image URL.\n      # @param match_all [Boolean] Add \"all\" as part of the URL.\n      # @return [String]\n      #\n      # @example\n      #   Faker::LoremFlickr.pixelated_image #=> \"https://loremflickr.com/p/300/300/all\"\n      #   Faker::LoremFlickr.pixelated_image(size: \"50x60\") #=> \"https://loremflickr.com/p/50/60/all\"\n      #   Faker::LoremFlickr.pixelated_image(size: \"50x60\", search_terms: ['sports']) #=> \"https://loremflickr.com/p/50/60/sports\"\n      #   Faker::LoremFlickr.pixelated_image(size: \"50x60\", search_terms: ['sports', 'fitness']) #=> \"https://loremflickr.com/p/50/60/sports,fitness\"\n      #   Faker::LoremFlickr.pixelated_image(size: \"50x60\", search_terms: ['sports', 'fitness'], match_all: true) #=> \"https://loremflickr.com/p/50/60/sports,fitness/all\"","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/faker-ruby/faker/blob/cca4184947e09fdd02afb8b89d25a9c8ebc7274e/lib/faker/default/lorem_flickr.rb#L27-L63","documentation":"Raised by Faker::LoremFlickr.grayscale_image when the search_terms array is empty. The guard `unless search_terms.any?` fires before the URL is built, because a grayscale LoremFlickr URL must end in at least one search keyword (the default is ['all']).","triggerScenarios":"Faker::LoremFlickr.grayscale_image(search_terms: []) or search_terms: [nil] (nil entries fail .any? only if all are nil — an array of only nil/blank values from params filtering, e.g. search_terms: params[:tags].presence || []).","commonSituations":"Forwarding user-selected tags straight into the call: `search_terms: params[:tags].split(',')` when the param is blank yields []; helper methods that build search_terms dynamically and sometimes produce an empty array; refactoring from the default ['all'] to dynamic terms.","solutions":["Pass a non-empty array, e.g. search_terms: ['all'] or ['nature'].","Default empty input before calling: `terms = params[:tags].presence&.split(',') || ['all']`.","Use compact/blank-stripping when building the array so it never consists solely of nils."],"exampleFix":"# before\nFaker::LoremFlickr.grayscale_image(search_terms: tags.select { |t| t == chosen }) # [] when nothing chosen\n\n# after\nterms = tags.select { |t| t == chosen }\nterms = ['all'] if terms.empty?\nFaker::LoremFlickr.grayscale_image(search_terms: terms)","handlingStrategy":"validation","validationCode":"terms = search_terms.to_a.compact.map(&:strip).reject(&:blank?)\nterms = ['all'] if terms.empty?\nFaker::LoremFlickr.grayscale_image(search_terms: terms)","typeGuard":"def non_blank_terms?(terms)\n  terms.is_a?(Array) && terms.compact.any? { |t| t.to_s.strip != '' }\nend","tryCatchPattern":"begin\n  Faker::LoremFlickr.grayscale_image(search_terms: terms)\nrescue ArgumentError\n  Faker::LoremFlickr.grayscale_image # default ['all']\nend","preventionTips":["Coalesce user-supplied tag lists to ['all'] before calling.","Compact and strip dynamically built arrays so nil/blank entries cannot empty them.","Treat empty search terms as 'use default' in one shared helper for all LoremFlickr variants."],"tags":["faker","argument-error","validation","image-url","loremflickr"],"backgroundTag":"empty-collection-argument","analyzedSha":"cca4184947e09fdd02afb8b89d25a9c8ebc7274e","analyzedAt":"2026-08-21T16:25:39.145Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}