{"record":{"id":"62e962392a2910e2","repo":"redis/redis-rb","slug":"ranges-must-be-given-as-start-stop-pairs","errorCode":null,"errorMessage":"ranges must be given as start/stop pairs","messagePattern":"ranges must be given as start/stop pairs","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/redis/commands/arrays.rb","lineNumber":165,"sourceCode":"      # Delete elements in one or more inclusive index ranges.\n      #\n      # Ranges may overlap; each element is counted at most once. A range\n      # given with `start > stop` is processed in ascending order regardless.\n      #\n      # @example Delete two ranges\n      #   redis.ardelrange(\"foo\", 0, 2, 5, 7)\n      #     # => 6\n      # @example Ranges as pairs\n      #   redis.ardelrange(\"foo\", [0, 2], [5, 7])\n      #     # => 6\n      #\n      # @param [String] key\n      # @param [Integer, Array<Integer>] ranges one or more start/stop pairs,\n      #   as flat alternating integers or one array per range\n      # @return [Integer] the number of elements deleted\n      def ardelrange(key, *ranges)\n        ranges = ranges.flatten(1).map { |index| Integer(index) }\n        raise ArgumentError, \"ranges must be given as start/stop pairs\" if ranges.empty? || ranges.size.odd?\n\n        send_command([:ardelrange, key, *ranges])\n      end\n\n      # Insert one or more values at consecutive indices, beginning at the\n      # array's insert cursor. The cursor advances by one for each value.\n      #\n      # @see #arnext inspect the current cursor position\n      # @see #arseek reposition the cursor\n      #\n      # @param [String] key\n      # @param [String] values one or more values to insert\n      # @return [Integer] the last index where a value was inserted\n      def arinsert(key, *values)\n        send_command([:arinsert, key, *values])\n      end\n\n      # Set the insert cursor of an array to a specific index.","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/commands/arrays.rb#L147-L183","documentation":"ardelrange accepts one or more inclusive start/stop index ranges, as flat alternating integers or one array per range. It flattens the arguments, maps each through Integer(), and raises ArgumentError 'ranges must be given as start/stop pairs' when the list is empty or odd-length — a start bound without its stop.","triggerScenarios":"redis.ardelrange('foo') with no ranges; redis.ardelrange('foo', 0, 2, 5) — odd count; passing [ [0, 2], [5] ] where an inner array holds one element. (Non-integer strings fail earlier inside Integer() with a different error.)","commonSituations":"Ranges assembled at runtime (user-selected ranges, batched deletions) where the last pair was truncated; off-by-one when slicing a flat bounds array; converting Range objects and forgetting to emit both begin and end.","solutions":["Supply complete pairs: ardelrange(key, 0, 2, 5, 7) or ardelrange(key, [0, 2], [5, 7])","When carrying Ruby Range objects, convert each to [range.begin, range.end] first","Validate dynamic bounds before calling: flattened list must be non-empty and even-length"],"exampleFix":"# before\nredis.ardelrange('foo', 0, 2, 5)  # missing stop: ArgumentError\n\n# after\nredis.ardelrange('foo', 0, 2, 5, 7)\nredis.ardelrange('foo', [0, 2], [5, 7])  # pair form","handlingStrategy":"validation","validationCode":"bounds = ranges.flatten(1)\nraise ArgumentError, 'need start/stop pairs' if bounds.empty? || bounds.size.odd?\nredis.ardelrange(key, *bounds)","typeGuard":null,"tryCatchPattern":"begin\n  redis.ardelrange(key, *bounds)\nrescue ArgumentError => e\n  raise ArgumentError, \"bad ranges (#{bounds.inspect}): #{e.message}\"\nend","preventionTips":["Emit [range.begin, range.end] per Range object when converting","Keep bounds in pair arrays ([start, stop]) rather than a flat list in your own code","Validate even length before splatting dynamic bounds"],"tags":["argument-validation","arrays","range"],"backgroundTag":"argument-count-mismatch","analyzedSha":"2ba9010b91dab9e0fde1fbae3a9aae003f8bc307","analyzedAt":"2026-08-23T03:54:57.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}