Skip to content

Commit 8853c03

Browse files
feat: improve error handling for channel watching and drop retrieval
1 parent 0dd7a67 commit 8853c03

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,14 @@ async fn watch_sync (clients: Vec<Arc<TwitchClient>>, rx: Receiver<Channel>, not
401401
let mut old_stream_name = String::new();
402402
let mut now_watching_stream: Option<(String, String, String)> = None;
403403

404-
let mut watching = rx.recv().await.unwrap();
404+
let mut watching = match rx.recv().await {
405+
Ok(w) => w,
406+
Err(e) => {
407+
tracing::debug!("{e}");
408+
tracing::error!("Failed to receive initial channel to watch. Watch synchronization will not start for this client");
409+
return ;
410+
}
411+
};
405412
loop {
406413
match rx.try_recv() {
407414
Ok(channel) => watching = channel,
@@ -478,7 +485,10 @@ async fn drop_sync(clients: Vec<Arc<TwitchClient>>, tx: Sender<String>, cache_pa
478485
bar.set_message("Initialization...");
479486
bar.enable_steady_tick(Duration::from_millis(500));
480487

481-
let mut watching = rx_watch.recv().await.unwrap();
488+
let mut watching = match rx_watch.recv().await {
489+
Ok(channel) => channel,
490+
Err(_) => return,
491+
};
482492
let mut last_drop_id = String::new();
483493

484494
loop {

src/stream.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ pub async fn filter_streams (client: Arc<TwitchClient>, campaigns_arc: Arc<Mutex
4242
if count >= MAX_TOPICS {
4343
break;
4444
}
45-
let avaiable_drops = retry!(client.get_available_drops_for_channel(&channel.id));
45+
let avaiable_drops = match retry_backup(|| client.get_available_drops_for_channel(&channel.id)).await {
46+
Ok(drops) => drops,
47+
Err(e) => {
48+
tracing::error!("{e}");
49+
continue;
50+
}
51+
};
4652
if avaiable_drops.viewerDropCampaigns.is_some() {
4753
video_vec.insert(Channel { channel_id: channel.id, channel_login: channel.name });
4854
count += 1
@@ -65,7 +71,13 @@ pub async fn filter_streams (client: Arc<TwitchClient>, campaigns_arc: Arc<Mutex
6571
break;
6672
}
6773
if stream_info.stream.is_some() {
68-
let available_drops = retry!(client.get_available_drops_for_channel(&channel.broadcaster.id));
74+
let available_drops = match retry_backup(|| client.get_available_drops_for_channel(&channel.broadcaster.id)).await {
75+
Ok(drops) => drops,
76+
Err(e) => {
77+
tracing::error!("{e}");
78+
continue;
79+
}
80+
};
6981
if available_drops.viewerDropCampaigns.is_some() {
7082
video_vec.insert(Channel { channel_id: channel.broadcaster.id, channel_login: channel.broadcaster.login });
7183
count += 1

0 commit comments

Comments
 (0)