refactor: remove thiserror for now

This commit is contained in:
ThetaDev 2022-09-19 13:24:12 +02:00
parent 94c9a264a4
commit df6543d62e
5 changed files with 14 additions and 65 deletions

View file

@ -26,7 +26,6 @@ quick-js = { path = "../quickjs-rs" }
once_cell = "1.12.0"
fancy-regex = "0.10.0"
anyhow = "1.0"
thiserror = "1.0.31"
url = "2.2.2"
log = "0.4.17"
reqwest = {version = "0.11.11", default-features = false, features = ["json", "gzip", "brotli", "stream"]}

View file

@ -18,7 +18,7 @@ DRM: 1bfOsni7EgI
Album with unknown artists: https://music.youtube.com/playlist?list=OLAK5uy_mEX9ljZeeEWgTM1xLL1isyiGaWXoPyoOk
Throttling issue: Y8JFxS1HlDo
Comment by artist: 3pv_rHKnwAs
# Playlists
962 Songs: PL4lEESSgxM_5O81EvKCmBIm_JT5Q7JeaI

View file

@ -259,21 +259,22 @@ fn map_playlist_items(
}
impl Paginator<PlaylistVideo> {
pub async fn next(&self, query: RustyPipeQuery) -> Result<Self, crate::error::Error> {
match &self.ctoken {
Some(ctoken) => Ok(query.get_playlist_continuation(ctoken).await?),
None => Err(crate::error::Error::PaginatorExhausted),
}
pub async fn next(&self, query: RustyPipeQuery) -> Result<Option<Self>> {
Ok(match &self.ctoken {
Some(ctoken) => Some(query.get_playlist_continuation(ctoken).await?),
None => None,
})
}
pub async fn extend(&mut self, query: RustyPipeQuery) -> Result<(), crate::error::Error> {
pub async fn extend(&mut self, query: RustyPipeQuery) -> Result<bool> {
match self.next(query).await {
Ok(paginator) => {
Ok(Some(paginator)) => {
let mut items = paginator.items;
self.items.append(&mut items);
self.ctoken = paginator.ctoken;
Ok(())
Ok(true)
}
Ok(None) => Ok(false),
Err(e) => Err(e),
}
}
@ -281,11 +282,11 @@ impl Paginator<PlaylistVideo> {
pub async fn extend_pages(&mut self, query: RustyPipeQuery, n_pages: usize) -> Result<()> {
for _ in 0..n_pages {
match self.extend(query.clone()).await {
Err(crate::error::Error::PaginatorExhausted) => {
Ok(false) => {
break;
}
Err(e) => {
return Err(e.into());
return Err(e);
}
_ => {}
}
@ -296,11 +297,11 @@ impl Paginator<PlaylistVideo> {
pub async fn extend_limit(&mut self, query: RustyPipeQuery, n_items: usize) -> Result<()> {
while self.items.len() < n_items {
match self.extend(query.clone()).await {
Err(crate::error::Error::PaginatorExhausted) => {
Ok(false) => {
break;
}
Err(e) => {
return Err(e.into());
return Err(e);
}
_ => {}
}

View file

@ -1,50 +0,0 @@
/// Errors that can occur during the id extraction or the video download process.
#[derive(thiserror::Error, Debug)]
pub enum Error {
/*
#[error("the provided raw Id does not match any known Id-pattern")]
BadIdFormat,
#[cfg(feature = "fetch")]
#[error("the video you requested is unavailable:\n{0:#?}")]
VideoUnavailable(Box<crate::video_info::player_response::playability_status::PlayabilityStatus>),
#[cfg(feature = "download")]
#[error("the video contains no streams")]
NoStreams,
#[error(transparent)]
#[cfg(feature = "fetch")]
IO(#[from] std::io::Error),
#[error(transparent)]
#[cfg(feature = "fetch")]
Request(#[from] reqwest::Error),
#[error("YouTube returned an unexpected response: `{0}`")]
UnexpectedResponse(String),
#[error(transparent)]
#[cfg(feature = "fetch")]
QueryDeserialization(#[from] serde_qs::Error),
#[error(transparent)]
#[cfg(feature = "fetch")]
JsonDeserialization(#[from] serde_json::Error),
#[error(transparent)]
UrlParseError(#[from] url::ParseError),
#[error("{0}")]
Custom(String),
#[error("a potentially dangerous error occurred: {0}")]
Fatal(String),
#[error(
"the error, which occurred is not meant an error, but is used for internal comunication.\
This error should never be propagated to the public API."
)]
Internal(&'static str),
#[error("The internal channel has been closed")]
#[cfg(feature = "callback")]
ChannelClosed,
*/
#[error("paginator is exhausted")]
PaginatorExhausted,
// TODO: Remove anyhow
#[error(transparent)]
Anyhow(#[from] anyhow::Error),
}

View file

@ -12,7 +12,6 @@ mod util;
pub mod cache;
pub mod client;
pub mod download;
pub mod error;
pub mod model;
pub mod report;
pub mod timeago;