Replace some unwraps with more error logging
stable / fmt Details
stable / cross-${{ matrix.target }} (aarch64-unknown-linux-gnu) Details
stable / cross-${{ matrix.target }} (armv7-unknown-linux-gnueabihf) Details
stable / cross-${{ matrix.target }} (x86_64-unknown-linux-gnu) Details

This commit is contained in:
Hans Mündelein 2023-06-12 22:34:39 +02:00
parent 5d1a62c630
commit 902c0b903f
Signed by: hans
GPG Key ID: BA7B55E984CE74F4
1 changed files with 14 additions and 6 deletions

View File

@ -1,9 +1,9 @@
use crabidy_core::proto::crabidy::{Queue, Track}; use crabidy_core::proto::crabidy::{Queue, Track};
use rand::{seq::SliceRandom, thread_rng}; use rand::{seq::SliceRandom, thread_rng};
use std::time::SystemTime; use std::time::SystemTime;
use tracing::debug; use tracing::{debug, error};
#[derive(Clone)] #[derive(Clone, Debug)]
pub struct QueueManager { pub struct QueueManager {
created_at: SystemTime, created_at: SystemTime,
current_offset: usize, current_offset: usize,
@ -111,11 +111,15 @@ impl QueueManager {
if self.shuffle { if self.shuffle {
self.shuffle_all(); self.shuffle_all();
} }
let current_offset = self let Some(current_offset) = self
.play_order .play_order
.iter() .iter()
.position(|&i| i == current_position as usize) .position(|&i| i == current_position as usize)
.unwrap(); else {
error!("invalid current position");
error!("queue: {:#?}", self);
return false
};
if self.shuffle { if self.shuffle {
self.play_order.swap(0, current_offset); self.play_order.swap(0, current_offset);
self.current_offset = 0; self.current_offset = 0;
@ -184,11 +188,15 @@ impl QueueManager {
if *pos == self.current_position() as u32 { if *pos == self.current_position() as u32 {
play_next = true; play_next = true;
} }
let offset = self let Some(offset) = self
.play_order .play_order
.iter() .iter()
.position(|&i| i == *pos as usize) .position(|&i| i == *pos as usize)
.unwrap(); else {
error!("invalid current position");
error!("queue: {:#?}", self);
return None
};
if offset < self.current_offset { if offset < self.current_offset {
self.current_offset -= 1; self.current_offset -= 1;
} }