Skip to content

record_accessor: raise ConfigError for a non-integer array index - #5596

Merged
Watson1978 merged 1 commit into
fluent:masterfrom
lbarrosby:fix-record-accessor-index
Nov 6, 2026
Merged

Watson1978 merged 1 commit into
fluent:masterfrom
lbarrosby:fix-record-accessor-index

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
Fixes #5595

What this PR does / why we need it:

A record_accessor key with a non-integer array index, such as $.a[x] or $['a'][x], reached Integer(index_value) and raised ArgumentError. Fluentd stopped with "unexpected error" (or a backtrace on 1.16) instead of a config error.

Now both the dot and the bracket parsers raise Fluent::ConfigError, like the other syntax errors next to them.

Before:

$.a[x]: ArgumentError: invalid value for Integer(): "x"

After, with the configuration from the issue and fluentd --dry-run:

[error]: config error file="f.conf" error_class=Fluent::ConfigError error="array index must be an integer: 'x'. Invalid syntax: $.a[x]"

Tests: added both keys to the two invalid syntax data sets in test/plugin_helper/test_record_accessor.rb. They fail on master with ArgumentError and pass with this change.

Docs Changes:

N/A

Release Note:

record_accessor: report a non-integer array index such as $.a[x] as a config error.

A key such as `$.a[x]` or `$['a'][x]` made Integer() raise
ArgumentError, so Fluentd stopped with an unexpected error instead of
reporting a config error with the file name. Convert it to
Fluent::ConfigError like the other syntax errors next to it.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@Watson1978 Watson1978 added this to the v1.21.0 milestone Nov 6, 2026
@Watson1978 Watson1978 added the backport to v1.19 We will backport this fix to the LTS branch label Nov 6, 2026
@Watson1978
Watson1978 merged commit d4a976b into fluent:master Nov 6, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.19 We will backport this fix to the LTS branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

record_accessor raises ArgumentError instead of ConfigError for an array index that is not an integer

2 participants