mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
apply suggestions, improve errors
This commit is contained in:
parent
51eb100e77
commit
60378c6fb1
4 changed files with 20 additions and 12 deletions
|
@ -50,6 +50,8 @@ use tokio::{sync::mpsc, time::sleep};
|
||||||
pub enum SpircError {
|
pub enum SpircError {
|
||||||
#[error("response payload empty")]
|
#[error("response payload empty")]
|
||||||
NoData,
|
NoData,
|
||||||
|
#[error("{0} had no uri")]
|
||||||
|
NoUri(&'static str),
|
||||||
#[error("message pushed for another URI")]
|
#[error("message pushed for another URI")]
|
||||||
InvalidUri(String),
|
InvalidUri(String),
|
||||||
#[error("tried resolving not allowed context: {0:?}")]
|
#[error("tried resolving not allowed context: {0:?}")]
|
||||||
|
@ -64,7 +66,7 @@ impl From<SpircError> for Error {
|
||||||
fn from(err: SpircError) -> Self {
|
fn from(err: SpircError) -> Self {
|
||||||
use SpircError::*;
|
use SpircError::*;
|
||||||
match err {
|
match err {
|
||||||
NoData | NotAllowedContext(_) => Error::unavailable(err),
|
NoData | NoUri(_) | NotAllowedContext(_) => Error::unavailable(err),
|
||||||
InvalidUri(_) | FailedDealerSetup => Error::aborted(err),
|
InvalidUri(_) | FailedDealerSetup => Error::aborted(err),
|
||||||
UnknownEndpoint(_) => Error::unimplemented(err),
|
UnknownEndpoint(_) => Error::unimplemented(err),
|
||||||
}
|
}
|
||||||
|
@ -1037,7 +1039,11 @@ impl SpircTask {
|
||||||
.map(|o| o.repeating_track.unwrap_or_default())
|
.map(|o| o.repeating_track.unwrap_or_default())
|
||||||
.unwrap_or_else(|| self.connect_state.repeat_track());
|
.unwrap_or_else(|| self.connect_state.repeat_track());
|
||||||
|
|
||||||
let context_uri = play.context.uri.as_ref().ok_or(SpircError::NoData)?.clone();
|
let context_uri = play
|
||||||
|
.context
|
||||||
|
.uri
|
||||||
|
.clone()
|
||||||
|
.ok_or(SpircError::NoUri("context"))?;
|
||||||
|
|
||||||
self.handle_load(
|
self.handle_load(
|
||||||
SpircLoadCommand {
|
SpircLoadCommand {
|
||||||
|
@ -1093,7 +1099,7 @@ impl SpircTask {
|
||||||
|
|
||||||
fn handle_transfer(&mut self, mut transfer: TransferState) -> Result<(), Error> {
|
fn handle_transfer(&mut self, mut transfer: TransferState) -> Result<(), Error> {
|
||||||
let mut ctx_uri = match transfer.current_session.context.uri {
|
let mut ctx_uri = match transfer.current_session.context.uri {
|
||||||
None => Err(SpircError::NoData)?,
|
None => Err(SpircError::NoUri("transfer context"))?,
|
||||||
Some(ref uri) => uri.clone(),
|
Some(ref uri) => uri.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1517,7 +1523,9 @@ impl SpircTask {
|
||||||
&mut self,
|
&mut self,
|
||||||
playlist_modification_info: PlaylistModificationInfo,
|
playlist_modification_info: PlaylistModificationInfo,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let uri = playlist_modification_info.uri.ok_or(SpircError::NoData)?;
|
let uri = playlist_modification_info
|
||||||
|
.uri
|
||||||
|
.ok_or(SpircError::NoUri("playlist modification"))?;
|
||||||
let uri = String::from_utf8(uri)?;
|
let uri = String::from_utf8(uri)?;
|
||||||
|
|
||||||
if self.connect_state.context_uri() != &uri {
|
if self.connect_state.context_uri() != &uri {
|
||||||
|
|
|
@ -44,14 +44,15 @@ const SPOTIFY_MAX_NEXT_TRACKS_SIZE: usize = 80;
|
||||||
pub enum StateError {
|
pub enum StateError {
|
||||||
#[error("the current track couldn't be resolved from the transfer state")]
|
#[error("the current track couldn't be resolved from the transfer state")]
|
||||||
CouldNotResolveTrackFromTransfer,
|
CouldNotResolveTrackFromTransfer,
|
||||||
#[error("message field {0} was not available")]
|
|
||||||
MessageFieldNone(String),
|
|
||||||
#[error("context is not available. type: {0:?}")]
|
#[error("context is not available. type: {0:?}")]
|
||||||
NoContext(ContextType),
|
NoContext(ContextType),
|
||||||
#[error("could not find track {0:?} in context of {1}")]
|
#[error("could not find track {0:?} in context of {1}")]
|
||||||
CanNotFindTrackInContext(Option<usize>, usize),
|
CanNotFindTrackInContext(Option<usize>, usize),
|
||||||
#[error("currently {action} is not allowed because {reason}")]
|
#[error("currently {action} is not allowed because {reason}")]
|
||||||
CurrentlyDisallowed { action: String, reason: String },
|
CurrentlyDisallowed {
|
||||||
|
action: &'static str,
|
||||||
|
reason: String,
|
||||||
|
},
|
||||||
#[error("the provided context has no tracks")]
|
#[error("the provided context has no tracks")]
|
||||||
ContextHasNoTracks,
|
ContextHasNoTracks,
|
||||||
#[error("playback of local files is not supported")]
|
#[error("playback of local files is not supported")]
|
||||||
|
@ -65,7 +66,6 @@ impl From<StateError> for Error {
|
||||||
use StateError::*;
|
use StateError::*;
|
||||||
match err {
|
match err {
|
||||||
CouldNotResolveTrackFromTransfer
|
CouldNotResolveTrackFromTransfer
|
||||||
| MessageFieldNone(_)
|
|
||||||
| NoContext(_)
|
| NoContext(_)
|
||||||
| CanNotFindTrackInContext(_, _)
|
| CanNotFindTrackInContext(_, _)
|
||||||
| ContextHasNoTracks
|
| ContextHasNoTracks
|
||||||
|
|
|
@ -196,7 +196,7 @@ impl ConnectState {
|
||||||
let mut new_context = self.state_context_from_page(
|
let mut new_context = self.state_context_from_page(
|
||||||
page,
|
page,
|
||||||
context.restrictions.take(),
|
context.restrictions.take(),
|
||||||
context.uri.as_ref(),
|
context.uri.as_deref(),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ impl ConnectState {
|
||||||
self.autoplay_context = Some(self.state_context_from_page(
|
self.autoplay_context = Some(self.state_context_from_page(
|
||||||
page,
|
page,
|
||||||
context.restrictions.take(),
|
context.restrictions.take(),
|
||||||
context.uri.as_ref(),
|
context.uri.as_deref(),
|
||||||
Some(Provider::Autoplay),
|
Some(Provider::Autoplay),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ impl ConnectState {
|
||||||
&mut self,
|
&mut self,
|
||||||
page: ContextPage,
|
page: ContextPage,
|
||||||
restrictions: Option<Restrictions>,
|
restrictions: Option<Restrictions>,
|
||||||
new_context_uri: Option<&String>,
|
new_context_uri: Option<&str>,
|
||||||
provider: Option<Provider>,
|
provider: Option<Provider>,
|
||||||
) -> StateContext {
|
) -> StateContext {
|
||||||
let new_context_uri = new_context_uri.unwrap_or(self.context_uri());
|
let new_context_uri = new_context_uri.unwrap_or(self.context_uri());
|
||||||
|
|
|
@ -41,7 +41,7 @@ impl ConnectState {
|
||||||
.first()
|
.first()
|
||||||
{
|
{
|
||||||
Err(StateError::CurrentlyDisallowed {
|
Err(StateError::CurrentlyDisallowed {
|
||||||
action: "shuffle".to_string(),
|
action: "shuffle",
|
||||||
reason: reason.clone(),
|
reason: reason.clone(),
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue