From 2a2a8852ca1500c5c0b8e6de7638c33022c47ca5 Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Tue, 21 May 2024 12:33:40 +0200 Subject: [PATCH] Improve warning when harvest item cannot be deserialized This is a band aid fix and not perfect. When I added the `Unknown` variant to the enum, I wasn't aware that it was used when other variants fail to deserialize even with `kind: "event"`. So the warning there was misleading. It's still not perfect because I ideally want to print more information on the deseralization failure. And the `kind` strings are duplicated now. I think in the future, the `HarvestResponse` might have items of type `{ kind: String, #[serde(flatten)] body: serde_json::Value }` or something like that. And then we deserialize it manually in a second step. We will see. --- backend/src/sync/harvest/mod.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/backend/src/sync/harvest/mod.rs b/backend/src/sync/harvest/mod.rs index 6aec34292..c60d7c775 100644 --- a/backend/src/sync/harvest/mod.rs +++ b/backend/src/sync/harvest/mod.rs @@ -323,9 +323,23 @@ async fn store_in_db( removed_playlists += 1; } - HarvestItem::Unknown { kind, .. } => { - warn!("Unknown item of kind '{kind}' in harvest response. \ - You might need to update Tobira."); + HarvestItem::Unknown { kind, updated } => { + let known = [ + "event", + "event-deleted", + "series", + "series-deleted", + "playlist", + "playlist-deleted", + ]; + + if known.contains(&&*kind) { + warn!("Could not deserialize item in harvest response for \ + kind '{kind}' (updated {updated})"); + } else { + warn!("Unknown item of kind '{kind}' in harvest response. \ + You might need to update Tobira."); + } } } }