fluent/fluentd · error · Fluent::ConfigError

'[' found but ']' not found. Invalid syntax: #{orig_param}

Error message

'[' found but ']' not found. Invalid syntax: #{orig_param}

What it means

Fluent::ConfigError from Fluent::RecordAccessor's parse_bracket_notation. Once inside brackets with an unquoted value, the parser requires a ']' to close the index; a path ending before it, like $[0 or $[12, is incomplete and rejected with the original parameter echoed.

Source

Thrown at lib/fluent/plugin_helper/record_accessor.rb:187

            if in_bracket
              if param[0] == "'" || param[0] == '"'
                if i = param.index("']") || param.index('"]')
                  raise Fluent::ConfigError, "Mismatched quotes. Invalid syntax: #{orig_param}" unless param[0] == param[i]
                  result << param[1..i - 1]
                  param = param[i + 2..-1]
                  in_bracket = false
                else
                  raise Fluent::ConfigError, "Incomplete bracket. Invalid syntax: #{orig_param}"
                end
              else
                if i = param.index(']')
                  index_value = param[0..i - 1]
                  raise Fluent::ConfigError, "missing array index in '[]'. Invalid syntax: #{param}" if index_value == ']'
                  result << Integer(index_value)
                  param = param[i + 1..-1]
                  in_bracket = false
                else
                  raise Fluent::ConfigError, "'[' found but ']' not found. Invalid syntax: #{orig_param}"
                end
              end
            else
              if i = param.index('[')
                param = param[i + 1..-1]
                in_bracket = true
              else
                raise Fluent::ConfigError, "found more characters after ']'. Invalid syntax: #{orig_param}"
              end
            end
          end

          raise Fluent::ConfigError, "empty keys in bracket notation" if result.empty?

          result
        end
      end
    end

View on GitHub (pinned to dd45c6e18d)

Solutions

  1. Close the bracket: $[0]
  2. Use the equivalent dot form for indexes on nested fields: $.arr[0]
  3. Lint generated accessor paths for balanced brackets

Example fix

# before
accessor = record_accessor_create('$[1')

# after
accessor = record_accessor_create('$[1]')
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, 'unbalanced brackets in path' if param.count('[') != param.count(']')
accessor = record_accessor_create(param)

Try / catch

begin
  Fluent::RecordAccessor::Accessor.new(param)
rescue Fluent::ConfigError => e
  raise ArgumentError, "unclosed bracket in #{param.inspect}"
end

Prevention

When it happens

Trigger: record_accessor_create with a bracket-notation path whose last bracket never closes: $[0, $[1]['k, $["a"][2 (only the numeric bracket is unclosed in valid cases).

Common situations: Hand-trimming paths when editing configs and dropping the final ']'; programmatic path assembly that appends an index without the closer.

Related errors


AI-assisted analysis of fluent/fluentd@dd45c6e18d (2026-08-21). Data as JSON: /api/errors/73d5716d25d7585a. Report an issue: GitHub.