Skip to content

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

Open
lbarrosby wants to merge 1 commit into
fluent:masterfrom
lbarrosby:fix-record-accessor-index
Open

lbarrosby wants to merge 1 commit into
fluent:masterfrom
lbarrosby:fix-record-accessor-index

Conversation

@lbarrosby

Copy link
Copy Markdown

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

1 participant