Report a failed podcast search without ending the music search

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sanapachandClaude Opus 5.5 committed 2026-11-20 15:12:52 +02:00
1 parent 678c7b8211
commit 2ea3f7b337
7 files changed
+119 -31

No files matched your search

+45 -21
View File
@@ -282,7 +282,13 @@ impl Federation {
}
/// The `federation.podcast` events of a search for `user_id`, numbered
/// after the music events (see [`podcast_events`]).
/// after the music events (see [`podcast_events`]), and the
/// `podcast_discovery` state for `search.completed`.
///
/// Never fails: when the hits cannot be prepared for the account (a
/// database error) they are dropped and the state is `failed`, so the
/// music results stand and the browser can say the podcast search
/// failed.
pub async fn podcast_search_events(
&self,
search_id: &str,
@@ -290,28 +296,46 @@ impl Federation {
user_id: i64,
music: &MusicSearch,
podcasts: PodcastSearch,
) -> Result<Vec<SearchEvent>> {
) -> (&'static str, Vec<SearchEvent>) {
let state = podcasts.state();
let PodcastSearch::Found(hits) = podcasts else {
return Ok(Vec::new());
return (state, Vec::new());
};
let pool = self.pool().await?;
let first_sequence = music.events.len() as u64 + 1;
let events = podcast_events(
&pool,
user_id,
search_id,
query.trim(),
&music.items,
first_sequence,
hits,
)
.await?;
tracing::info!(
search_id,
podcasts = events.len(),
"public podcast hits ready"
);
Ok(events)
if hits.is_empty() {
return (state, Vec::new());
}
let events = async {
let pool = self.pool().await?;
let first_sequence = music.events.len() as u64 + 1;
podcast_events(
&pool,
user_id,
search_id,
query.trim(),
&music.items,
first_sequence,
hits,
)
.await
};
match events.await {
Ok(events) => {
tracing::info!(
search_id,
podcasts = events.len(),
"public podcast hits ready"
);
(state, events)
}
Err(error) => {
// Only the error: never the query or the hits.
tracing::warn!(
search_id,
"public podcast hits could not be prepared: {error:#}"
);
("failed", Vec::new())
}
}
}
}
+1
View File
@@ -465,6 +465,7 @@ translations! {
player_podcast_request_failed: "Request failed", "Запрос не выполнен";
player_podcast_found_title: "Podcasts", "Подкасты";
player_podcast_type: "Podcast", "Подкаст";
player_podcast_found_failed: "The podcast search did not answer this time; music results are complete.", "Поиск подкастов сейчас не ответил; результаты по музыке полные.";
player_podcast_found_subscribed: "Already subscribed", "Уже подписан";
player_podcast_found_open: "Open", "Открыть";
player_podcast_found_subscribing: "Subscribing…", "Подписываемся…";
+4 -4
View File
@@ -7507,11 +7507,11 @@ async fn federation_search_events_handler(
let podcasts = podcasts
.await
.unwrap_or(crate::federation::client::PodcastSearch::Failed);
let podcast_discovery = podcasts.state();
let podcast_events = federation
// A podcast search or ranking failure only drops the
// podcast hits: `search.completed` reports it.
let (podcast_discovery, podcast_events) = federation
.podcast_search_events(&body_search_id, &q, user_id, &music, podcasts)
.await
.map_err(|err| cot::Error::internal(err.to_string()))?;
.await;
for event in &podcast_events {
last_sequence = event.sequence;
yield search_event_frame(event)?;
+34
View File
@@ -367,6 +367,40 @@ mod tests {
assert_eq!(http_url(None), None);
}
#[tokio::test]
async fn podcast_hits_that_cannot_be_prepared_are_reported_as_failed() {
use crate::federation::client::{MusicSearch, PodcastSearch};
// The federation handle of a unit test has no database: ranking the
// hits for the account fails. The search still completes.
let federation = crate::federation::handle();
let music = MusicSearch {
events: Vec::new(),
items: vec![music("Night Radio Theme")],
};
let (state, events) = federation
.podcast_search_events(
"search",
"night radio",
1,
&music,
PodcastSearch::Found(vec![hit("a.xml", "Night Radio")]),
)
.await;
assert_eq!(state, "failed");
assert!(events.is_empty());
for (search, expected) in [
(PodcastSearch::Found(Vec::new()), "running"),
(PodcastSearch::Off, "off"),
(PodcastSearch::Failed, "failed"),
] {
let (state, events) = federation
.podcast_search_events("search", "night radio", 1, &music, search)
.await;
assert_eq!(state, expected);
assert!(events.is_empty());
}
}
#[test]
fn a_preview_lists_seasons_and_the_newest_episodes() {
let xml = r#"<?xml version="1.0"?>