Compare commits

...

2 commits

Author SHA1 Message Date
9a652d851f
fix: improve VecLogErr messages
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-11-24 17:40:05 +01:00
9d243fa0ad
fix: parsing text components with empty navigation endpoints 2023-11-24 17:22:35 +01:00
2 changed files with 14 additions and 20 deletions

View file

@ -3,7 +3,7 @@ use std::convert::TryFrom;
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Deserializer};
use serde_with::{serde_as, DeserializeAs, VecSkipError};
use serde_with::{serde_as, DefaultOnError, DeserializeAs, VecSkipError};
use crate::{
client::response::url_endpoint::{
@ -122,10 +122,13 @@ struct RichTextInternal {
}
/// TextLinkRun is a single component from a YouTube text with links
#[serde_as]
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct RichTextRun {
text: String,
#[serde(default)]
#[serde_as(as = "DefaultOnError")]
navigation_endpoint: Option<NavigationEndpoint>,
}

View file

@ -20,13 +20,6 @@ where
where
D: serde::Deserializer<'de>,
{
#[derive(serde::Deserialize)]
#[serde(untagged)]
enum GoodOrError<T> {
Good(T),
Error(serde_json::Value),
}
struct SeqVisitor<T>(PhantomData<T>);
impl<'de, T> Visitor<'de> for SeqVisitor<T>
@ -46,16 +39,14 @@ where
let mut values = Vec::with_capacity(seq.size_hint().unwrap_or_default());
let mut warnings = Vec::new();
while let Some(value) = seq.next_element()? {
match value {
GoodOrError::<T>::Good(value) => {
values.push(value);
}
GoodOrError::<T>::Error(value) => {
warnings.push(format!(
"error deserializing item: {}",
serde_json::to_string(&value).unwrap_or_default()
));
loop {
match seq.next_element::<T>() {
Ok(val) => match val {
Some(val) => values.push(val),
None => break,
},
Err(e) => {
warnings.push(format!("error deserializing item: {e}"));
}
}
}
@ -186,8 +177,8 @@ mod tests {
insta::assert_debug_snapshot!(res.items.warnings, @r###"
[
"error deserializing item: {\"xyz\":\"i2\"}",
"error deserializing item: {\"namra\":\"i4\"}",
"error deserializing item: missing field `name` at line 1 column 40",
"error deserializing item: missing field `name` at line 1 column 73",
]
"###);
}