fix handling empty data
Some checks failed
CI / build (push) Successful in 44s
CI / checks (push) Failing after 1m3s
CI / build-nixpkgs (push) Has been skipped

This commit is contained in:
Robin Appelman 2025-10-03 15:46:03 +02:00
commit dd4b6260a1

View file

@ -247,17 +247,36 @@ pub struct FullLogLine {
pub user_agent: String, pub user_agent: String,
pub version: TinyAsciiStr<16>, pub version: TinyAsciiStr<16>,
pub exception: Option<FullException>, pub exception: Option<FullException>,
#[serde(default)] #[serde(default, deserialize_with = "deserialize_data")]
pub data: HashMap<String, String>, pub data: HashMap<String, String>,
} }
fn deserialize_data<'de, D: Deserializer<'de>>(
deserializer: D,
) -> Result<HashMap<String, String>, D::Error> {
#[derive(Deserialize)]
#[serde(untagged)]
enum Data {
Data(HashMap<String, String>),
#[allow(dead_code)]
Empty(Vec<()>),
}
let data = Data::deserialize(deserializer)?;
Ok(match data {
Data::Data(data) => data,
Data::Empty(_) => HashMap::default(),
})
}
impl FullLogLine { impl FullLogLine {
pub fn has_data(&self) -> bool { pub fn has_data(&self) -> bool {
self.data.keys().any(|key| key.as_str() != "app") self.data.keys().any(|key| key.as_str() != "app")
} }
pub fn data(&self) -> impl Iterator<Item = (&str, &str)> { pub fn data(&self) -> impl Iterator<Item = (&str, &str)> {
self.data.iter().map(|(key, value)| (key.as_str(), value.as_str())) self.data
.iter()
.map(|(key, value)| (key.as_str(), value.as_str()))
.filter(|(key, _)| *key != "app") .filter(|(key, _)| *key != "app")
} }
} }