{"record":{"id":"466e0cbb61c135e3","repo":"arsduo/koala","slug":"wrong-number-of-arguments-for-put-method-pho","errorCode":null,"errorMessage":"Wrong number of arguments for put_#{method == \"photos\" ? \"picture\" : \"video\"}","messagePattern":"Wrong number of arguments for put_#(.+?)","errorType":"validation","errorClass":"Koala::KoalaError","httpStatus":null,"severity":"error","filePath":"lib/koala/api/graph_api_methods.rb","lineNumber":473,"sourceCode":"      #\n      # @return an array of results from your batch calls (as if you'd made them individually),\n      #         arranged in the same order they're made.\n      def batch(http_options = {}, &block)\n        batch_client = GraphBatchAPI.new(self)\n        if block\n          yield batch_client\n          batch_client.execute(http_options)\n        else\n          batch_client\n        end\n      end\n\n      private\n\n      def parse_media_args(media_args, method)\n        # photo and video uploads can accept different types of arguments (see above)\n        # so here, we parse the arguments into a form directly usable in put_connections\n        raise KoalaError.new(\"Wrong number of arguments for put_#{method == \"photos\" ? \"picture\" : \"video\"}\") unless media_args.size.between?(1, 5)\n\n        args_offset = media_args[1].kind_of?(Hash) || media_args.size == 1 ? 0 : 1\n\n        args      = media_args[1 + args_offset] || {}\n        target_id = media_args[2 + args_offset] || \"me\"\n        options   = media_args[3 + args_offset] || {}\n\n        if url?(media_args.first)\n          # If media_args is a URL, we can upload without UploadableIO\n          # Video: https://developers.facebook.com/docs/graph-api/video-uploads\n          fb_expected_arg_name = method == \"photos\" ? :url : :file_url\n          args.merge!(fb_expected_arg_name => media_args.first)\n        else\n          args[\"source\"] = Koala::HTTPService::UploadableIO.new(*media_args.slice(0, 1 + args_offset))\n        end\n\n        [target_id, method, args, options]\n      end","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/arsduo/koala/blob/47d052063ef8b5644fb59e279da0b52687999f55/lib/koala/api/graph_api_methods.rb#L455-L491","documentation":"put_picture and put_video accept flexible positional arguments and normalize them in parse_media_args; it raises Koala::KoalaError ('Wrong number of arguments for put_picture' or '...put_video') when the splat holds fewer than 1 or more than 5 values (lib/koala/api/graph_api_methods.rb:473). The media source is mandatory; the parser understands at most five positions (source, optional content_type, args hash, target id, options). Since put_picture(*picture_args) has no required parameter, even a zero-argument call reaches this raise.","triggerScenarios":"api.put_picture with an empty argument list (params-driven code where the media argument was nil-stripped or the form carried no file), or a dynamically splatted array with six or more elements: api.put_picture(*[src, type, args, id, opts, extra]).","commonSituations":"Controller code forwarding params: api.put_picture(*media) where media is built dynamically and turns out empty; refactors that change put_picture's positional signature; code passing every optional argument positionally, placeholders included, past the five-slot maximum.","solutions":["Always pass the media source as the first argument: api.put_picture(source)","When splatting dynamic arrays, compact and bounds-check first: raise unless media.compact.size.between?(1, 5)","Use the documented positional forms instead of long chains: put_picture(file, content_type, args, target_id) already fits within the limit","If the source may be missing, default it explicitly (source || fallback_path) instead of forwarding nils"],"exampleFix":"# before\nmedia = [] # form posted without a file\napi.put_picture(*media) # => KoalaError: Wrong number of arguments for put_picture\n\n# after\nmedia = [params[:file], params[:message] ? {message: params[:message]} : {}, params[:id] || 'me']\nraise 'Please choose a file' if media[0].nil?\napi.put_picture(*media)","handlingStrategy":"validation","validationCode":"def valid_media_args?(media_args)\n  media_args.size.between?(1, 5)\nend\n\nraise ArgumentError, 'put_picture/put_video need 1-5 arguments (source first)' unless valid_media_args?(media)\napi.put_picture(*media)","typeGuard":null,"tryCatchPattern":"begin\n  api.put_picture(*media)\nrescue Koala::KoalaError => e\n  # argument-shape failure raised before any HTTP traffic — fix the call site; retrying cannot help\n  logger.error(\"put_picture received #{media.size} args: #{media.inspect}\")\n  raise\nend","preventionTips":["Never splat unvalidated arrays into put_picture/put_video — check the size is 1..5 first","Pass the media source explicitly as the first argument rather than forwarding params blindly","Prefer the documented forms put_picture(file, content_type, args, target_id) over long positional chains","Compact dynamic arg arrays and bail out with a user-facing message when the source is missing"],"tags":["argument-error","upload","put-picture","put-video","facebook-graph-api"],"backgroundTag":"wrong-argument-count","analyzedSha":"47d052063ef8b5644fb59e279da0b52687999f55","analyzedAt":"2026-08-23T10:19:03.891Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}