Open
Description
Vector Version
vector 0.13.1 (v0.13.1 x86_64-unknown-linux-gnu 2021-04-29)
Vector Configuration File
[sources.generator]
type = "generator"
format = "syslog"
[transforms.remap]
type = "remap"
inputs = ["generator"]
source = '''
. |= parse_regex(.message, r'^<\d+>(?P<a>\S+') ?? {}
.a = downcase(string(.a) ?? "")
'''
[sinks.console]
type = "console"
inputs = ["remap"]
encoding = "json"
Debug Output
error[E651]: unnecessary error coalescing operation
┌─ :2:17
│
2 │ .a = downcase(string(.a) ?? "")
│ ^^^^^^^^^^ -- -- this expression never resolves
│ │ │
│ │ remove this error coalescing operation
│ this expression can't fail
│
= see language documentation at https://vrl.dev
error[E110]: invalid argument type
┌─ :2:17
│
2 │ .a = downcase(string(.a) ?? "")
│ ^^^^^^^^^^^^^^^^
│ │
│ this expression resolves to the exact type "boolean"
│ but the parameter "value" expects the exact type "string"
Expected Behavior
Config should work as expected.
Actual Behavior
Config returns an error when using vector validate or running the config.
Example Data
Generated data.
Additional Context
Discussed this with @JeanMertz and he figured out that vector is making a wrong compile time assumption of the fields extracted using regex capture groups when parse_regex errors are suppressed using the " ?? {} " notation used above. A potential workaround is:
[sources.generator]
type = "generator"
format = "syslog"
[transforms.remap]
type = "remap"
inputs = ["generator"]
source = '''
. |= parse_regex(.message, r'^<\d+>(?P<a>\S+') ?? {"a": null}
.a = downcase(string(.a) ?? "")
'''
[sinks.console]
type = "console"
inputs = ["remap"]
encoding = "json"
References
Discussed on Discord in the support channel on 11/05/2021 around 12:00 CET.