{"record":{"id":"f8107b6199416dce","repo":"arsduo/koala","slug":"type-must-be-includedin-args-when-searching","errorCode":null,"errorMessage":"type must be includedin args when searching","messagePattern":"type must be includedin args when searching","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/koala/api/graph_api_methods.rb","lineNumber":354,"sourceCode":"      def delete_like(id, options = {}, &block)\n        # Unlikes a given object for the logged-in user\n        raise AuthenticationError.new(nil, nil, \"Unliking requires an access token\") unless access_token\n        graph_call(\"#{id}/likes\", {}, \"delete\", options, &block)\n      end\n\n      # Search for a given query among visible Facebook objects.\n      # See {http://developers.facebook.com/docs/reference/api/#searching Facebook documentation} for more information.\n      #\n      # @param search_terms the query to search for\n      # @param args object type and any additional arguments, such as fields, etc.\n      # @param options (see #get_object)\n      # @param block (see Koala::Facebook::API#api)\n      #\n      # @return [Koala::Facebook::API::GraphCollection] an array of search results\n      def search(search_terms, args = {}, options = {}, &block)\n        # Normally we wouldn't enforce Facebook API behavior, but the API fails with cryptic error\n        # messages if you fail to include a type term. For a convenience method, that is valuable.\n        raise ArgumentError, \"type must be includedin args when searching\" unless args[:type] || args[\"type\"]\n        graph_call(\"search\", args.merge(\"q\" => search_terms), \"get\", options, &block)\n      end\n\n      # Convenience Methods\n      # In general, we're trying to avoid adding convenience methods to Koala\n      # except to support cases where the Facebook API requires non-standard input\n      # such as JSON-encoding arguments, posts directly to objects, etc.\n\n      # Get a page's access token, allowing you to act as the page.\n      # Convenience method for @api.get_object(page_id, :fields => \"access_token\").\n      #\n      # @param id the page ID\n      # @param args (see #get_object)\n      # @param options (see #get_object)\n      # @param block (see Koala::Facebook::API#api)\n      #\n      # @return the page's access token (discarding expiration and any other information)\n      def get_page_access_token(id, args = {}, options = {}, &block)","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/arsduo/koala/blob/47d052063ef8b5644fb59e279da0b52687999f55/lib/koala/api/graph_api_methods.rb#L336-L372","documentation":"search raises ArgumentError ('type must be includedin args when searching' — the 'includedin' typo is verbatim in lib/koala/api/graph_api_methods.rb:354) when the args hash contains neither :type nor 'type'. The source comment explains why: Koala normally does not police Facebook's parameters, but the search endpoint fails with cryptic server-side errors when type is missing, so this convenience method validates it up front. Both symbol and string keys satisfy the guard.","triggerScenarios":"api.search('chocolate') or api.search('chocolate', limit: 10) — any call whose args omit type. Fixed by api.search('chocolate', type: 'page') with one of the documented types: post, user, page, event, group, place.","commonSituations":"Porting from old examples that show only the search terms; passing type under a different key (object_type:) or accidentally in the options hash (third parameter) instead of args (second); dynamic arg builders that drop blank values and remove type when a form field is empty.","solutions":["Pass the type in args: api.search('chocolate', type: 'page')","If you put type into options (the third argument), move it into args (the second) — the signature is search(search_terms, args = {}, options = {}, &block)","Whitelist types at your input boundary (user, page, event, group, place, post) so missing or invalid values fail before hitting Facebook","When migrating old code, grep for search( calls and add the type explicitly rather than relying on Facebook defaults"],"exampleFix":"# before\napi.search('koala gem') # => ArgumentError: type must be includedin args when searching\n\n# after\napi.search('koala gem', type: 'post', fields: 'message,from')\napi.search('blue bottle', 'type' => 'place', 'center' => '37.77,-122.41', 'distance' => 1000)","handlingStrategy":"validation","validationCode":"SEARCH_TYPES = %w[user page event group place post].freeze\n\ndef safe_search(api, terms, args)\n  type = args[:type] || args['type']\n  raise ArgumentError, \"args[:type] must be one of #{SEARCH_TYPES.join(', ')}\" unless SEARCH_TYPES.include?(type)\n  api.search(terms, args)\nend","typeGuard":null,"tryCatchPattern":"begin\n  api.search(terms, args)\nrescue ArgumentError => e\n  # local validation failure — surface to the caller, do not retry\n  render json: {error: e.message}, status: 400\nend","preventionTips":["Treat type as a required argument of search, not an optional one","Validate type against the documented set (user, page, event, group, place, post) at your input boundary","Remember the order: search(terms, args, options) — type belongs in args, not options","Pin the exact message (including the 'includedin' typo) if legacy code rescues this ArgumentError"],"tags":["argument-error","search","required-parameter","facebook-graph-api"],"backgroundTag":"missing-required-parameter","analyzedSha":"47d052063ef8b5644fb59e279da0b52687999f55","analyzedAt":"2026-08-23T10:19:03.891Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}