Skip to content

Commit

Permalink
Don't emit invalid json on missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
gahag-cw committed Dec 2, 2024
1 parent 4e296b5 commit dbf2717
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,10 @@ where
self.keyed_values.insert(
SchemaKey::from(key.into()),
JsonValue::DynamicRawFromEvent(Box::new(|event, writer| {
event
.metadata()
.file()
.map_or(Ok(()), |file| write_escaped(writer, file))
match event.metadata().file() {
Some(file) => write_escaped(writer, file),
None => write!(writer, "null"),
}
})),
);
self
Expand All @@ -914,10 +914,10 @@ where
self.keyed_values.insert(
SchemaKey::from(key.into()),
JsonValue::DynamicRawFromEvent(Box::new(|event, writer| {
event
.metadata()
.line()
.map_or(Ok(()), |line| write!(writer, "{line}"))
match event.metadata().line() {
Some(line) => write!(writer, "{line}"),
None => write!(writer, "null"),
}
})),
);
self
Expand All @@ -942,9 +942,10 @@ where
self.keyed_values.insert(
SchemaKey::from(key.into()),
JsonValue::DynamicRawFromEvent(Box::new(|_event, writer| {
std::thread::current()
.name()
.map_or(Ok(()), |name| write_escaped(writer, name))
match std::thread::current().name() {
Some(name) => write_escaped(writer, name),
None => write!(writer, "null"),
}
})),
);
self
Expand Down

0 comments on commit dbf2717

Please sign in to comment.