redis/redis-rb · error · ArgumentError

field_or_args must be a Field object or an array

Error message

field_or_args must be a Field object or an array

What it means

Error "field_or_args must be a Field object or an array" thrown in redis/redis-rb.

Source

Thrown at lib/redis/commands/modules/search/miscellaneous.rb:356

      def ft_explain(index_name, query)
        send_command(["FT.EXPLAIN", index_name, query])
      end

      # Add a field to an existing index's schema (+FT.ALTER ... SCHEMA ADD+).
      #
      # @param index_name [String] the index name
      # @param field_or_args [Search::Field, Array] a {Search::Field} (rendered via +#to_args+) or a
      #   raw token array
      # @return [String] +"OK"+
      # @raise [ArgumentError] if +field_or_args+ is neither a Field nor an Array
      def ft_alter(index_name, field_or_args)
        args = [index_name, "SCHEMA", "ADD"]
        if field_or_args.respond_to?(:to_args)
          args += field_or_args.to_args
        elsif field_or_args.is_a?(Array)
          args += field_or_args
        else
          raise ArgumentError, "field_or_args must be a Field object or an array"
        end
        send_command([:"FT.ALTER", *args])
      end

      # Read the next batch of results from an aggregation cursor.
      #
      # @param index_name [String] the index name
      # @param cursor_id [Integer] the cursor id returned by a previous WITHCURSOR aggregation
      # @return [Search::AggregateResult] the next rows, with +#cursor+ set to the next cursor id
      #   (+0+ when exhausted)
      def ft_cursor_read(index_name, cursor_id)
        send_command(["FT.CURSOR", "READ", index_name, cursor_id]) { |reply| ResultParser.aggregate(reply) }
      end

      # Discard an aggregation cursor.
      #
      # @param index_name [String] the index name
      # @param cursor_id [Integer] the cursor id

View on GitHub (pinned to 2ba9010b91)

Solutions

  1. Pass a single Field object or an array of Field objects to the method.
  2. Convert raw hashes into Field objects before calling.

When it happens

Trigger: Thrown at lib/redis/commands/modules/search/miscellaneous.rb:356 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of redis/redis-rb@2ba9010b91 (2026-08-23). Data as JSON: /api/errors/7ed89a0e7539496e. Report an issue: GitHub.