{"record":{"id":"a0cc353e4f42d9a1","repo":"redis/redis-rb","slug":"index-requires-a-path","errorCode":null,"errorMessage":"index requires a path","messagePattern":"index requires a path","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/redis/commands/modules/json.rb","lineNumber":366,"sourceCode":"      # Remove and return an element from the array at +path+. When +path+ is omitted it defaults\n      # to the root; when +index+ is omitted it defaults to -1 (the last element).\n      #\n      # The popped element is returned as parsed JSON (a Ruby object), or as the unparsed JSON\n      # string when +raw: true+.\n      #\n      # @example\n      #   redis.json_arrpop(\"doc\", \"$.colors\", 0)\n      #     # => [\"black\"]\n      #\n      # @param [String] key\n      # @param [String] path an optional JSONPath to the target array (defaults to the root \"$\")\n      # @param [Integer] index an optional position to pop from (defaults to -1, the last element)\n      # @param [Boolean] raw return the unparsed JSON string(s) instead of parsed Ruby objects\n      # @return [Array, Object, nil] the popped value(s); an Array for a JSONPath, a single value\n      #   for a legacy path, nil for an empty array or a non-array match\n      # @raise [ArgumentError] if +index+ is given without a +path+\n      def json_arrpop(key, path = nil, index = nil, raw: false)\n        raise ArgumentError, \"index requires a path\" if !index.nil? && path.nil?\n\n        args = [:\"JSON.ARRPOP\", key]\n        if path\n          args << path\n          args << Integer(index) unless index.nil?\n        end\n\n        send_command(args) do |reply|\n          if reply.nil? || raw\n            reply\n          elsif reply.is_a?(Array)\n            reply.map { |value| value.nil? ? nil : ::JSON.parse(value) }\n          else\n            ::JSON.parse(reply)\n          end\n        end\n      end\n","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/commands/modules/json.rb#L348-L384","documentation":"json_arrpop takes positional optional path then optional index, mirroring the wire form JSON.ARRPOP key [path [index]]. An index is only meaningful relative to a path, and because the parameters are positional, an index with a nil path would be silently mis-bound (the index would travel where the server expects a path). The wrapper therefore raises ArgumentError when index is given without path (lib/redis/commands/modules/json.rb:366).","triggerScenarios":"redis.json_arrpop(\"doc\", 0) when trying to pop the first element of the root array, because 0 lands in the path slot; redis.json_arrpop(\"doc\", nil, -1) with an explicit nil path.","commonSituations":"Assuming the root array is implied the way it is in json_get; porting RedisJSON CLI examples that always show the $ path explicitly; wanting index 0 (the first element) and forgetting the \"$\" argument.","solutions":["Always pass the path when using an index: redis.json_arrpop(\"doc\", \"$\", 0)","For the common pop-last case, omit both: redis.json_arrpop(\"doc\")","Wrap the call in a keyword-based helper (path:, index:) to remove the positional trap"],"exampleFix":"// before\nredis.json_arrpop(\"doc\", 0)\n// after\nredis.json_arrpop(\"doc\", \"$\", 0)","handlingStrategy":"validation","validationCode":"def arrpop(redis, key, path: \"$\", index: nil)\n  raise ArgumentError, \"index requires a path\" if index && path.nil?\n  index ? redis.json_arrpop(key, path, index) : redis.json_arrpop(key, path)\nend","typeGuard":"index.nil? || !path.nil?","tryCatchPattern":"begin\n  redis.json_arrpop(key, path, index)\nrescue ArgumentError => e\n  raise UsageError, e.message\nend","preventionTips":["Treat path as required whenever index is used","Prefer a keyword-argument wrapper over the positional signature","Remember the root path is \"$\" and is never implied"],"tags":["redis-json","json-arrpop","argumenterror","positional-args"],"backgroundTag":"missing-required-argument","analyzedSha":"2ba9010b91dab9e0fde1fbae3a9aae003f8bc307","analyzedAt":"2026-08-23T03:54:57.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}