Skip to content

Commit

Permalink
enhancement: check VRL conditions return type at compile time (vector…
Browse files Browse the repository at this point in the history
…dotdev#17894)

closes: vectordotdev#17175 

As discussed offline with @fuchsnj, we do not need to handle fallible
conditions because providing a fallible condition already results in an
error.
  • Loading branch information
pront authored Jul 6, 2023
1 parent 604fea0 commit fa489f8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/conditions/vrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ impl ConditionalConfig for VrlConfig {
.to_string()
})?;

if !program.final_type_info().result.is_boolean() {
return Err("VRL conditions must return a boolean.".into());
}

if !warnings.is_empty() {
let warnings = Formatter::new(&self.source, warnings).colored().to_string();
warn!(message = "VRL compilation warning.", %warnings);
Expand Down Expand Up @@ -233,6 +237,12 @@ mod test {
Ok(()),
Ok(()),
),
(
log_event![],
r#""i_return_a_string""#,
Err("VRL conditions must return a boolean.".into()),
Ok(()),
),
];

for (event, source, build, check) in checks {
Expand Down

0 comments on commit fa489f8

Please sign in to comment.