Skip to content

Commit

Permalink
+address review about being conditionnaly fallible or infallible
Browse files Browse the repository at this point in the history
Signed-off-by: prognant <pierre.rognant@datadoghq.com>
  • Loading branch information
prognant committed Jun 18, 2021
1 parent 1b096b3 commit 6840c7e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/vrl/stdlib/src/encode_key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ impl Expression for EncodeKeyValueFn {
}

fn type_def(&self, _state: &state::Compiler) -> TypeDef {
TypeDef::new().bytes().fallible()
match &self.fields {
None => TypeDef::new().bytes().infallible(),
Some(_) => TypeDef::new().bytes().fallible(),
}
}
}

Expand Down Expand Up @@ -237,7 +240,7 @@ mod tests {
}
],
want: Ok("lvl=info"),
tdef: TypeDef::new().bytes().fallible(),
tdef: TypeDef::new().bytes().infallible(),
}

multiple_elements {
Expand All @@ -248,7 +251,7 @@ mod tests {
}
],
want: Ok("log_id=12345 lvl=info"),
tdef: TypeDef::new().bytes().fallible(),
tdef: TypeDef::new().bytes().infallible(),
}

string_with_spaces {
Expand All @@ -258,7 +261,7 @@ mod tests {
"msg" => "This is a log message"
}],
want: Ok(r#"lvl=info msg="This is a log message""#),
tdef: TypeDef::new().bytes().fallible(),
tdef: TypeDef::new().bytes().infallible(),
}

string_with_characters_to_escape {
Expand All @@ -270,7 +273,7 @@ mod tests {
"space key" => "foo"
}],
want: Ok(r#"another_field="some\\nfield\\and things" lvl=info msg="payload: {\"code\": 200}\\n" "space key"=foo"#),
tdef: TypeDef::new().bytes().fallible(),
tdef: TypeDef::new().bytes().infallible(),
}

nested_fields {
Expand All @@ -292,7 +295,7 @@ mod tests {
"event" => "log"
}],
want: Ok("agent.id=1234 agent.name=vector event=log log.file.path=encode_key_value.rs network.ip.0=127 network.ip.1=0 network.ip.2=0 network.ip.3=1 network.proto=tcp"),
tdef: TypeDef::new().bytes().fallible(),
tdef: TypeDef::new().bytes().infallible(),
}

fields_ordering {
Expand Down

0 comments on commit 6840c7e

Please sign in to comment.