Replace if Let Err(_) with .map_err().ok() patterns.
I dislike the indentation and the noise if let adds.
This commit is contained in:
parent
3132856efe
commit
bc6eeec663
@ -28,10 +28,10 @@ fn download_checker() -> Result<(), DataError> {
|
|||||||
})
|
})
|
||||||
.for_each(|ep| {
|
.for_each(|ep| {
|
||||||
ep.set_local_uri(None);
|
ep.set_local_uri(None);
|
||||||
if let Err(err) = ep.save() {
|
ep.save()
|
||||||
error!("Error while trying to update episode: {:#?}", ep);
|
.map_err(|err| error!("{}", err))
|
||||||
error!("{}", err);
|
.map_err(|_| error!("Error while trying to update episode: {:#?}", ep))
|
||||||
};
|
.ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -48,12 +48,11 @@ fn played_cleaner(cleanup_date: DateTime<Utc>) -> Result<(), DataError> {
|
|||||||
.for_each(|ep| {
|
.for_each(|ep| {
|
||||||
let limit = ep.played().unwrap();
|
let limit = ep.played().unwrap();
|
||||||
if now_utc > limit {
|
if now_utc > limit {
|
||||||
if let Err(err) = delete_local_content(ep) {
|
delete_local_content(ep)
|
||||||
error!("Error while trying to delete file: {:?}", ep.local_uri());
|
.map(|_| info!("Episode {:?} was deleted succesfully.", ep.local_uri()))
|
||||||
error!("{}", err);
|
.map_err(|err| error!("Error: {}", err))
|
||||||
} else {
|
.map_err(|_| error!("Failed to delete file: {:?}", ep.local_uri()))
|
||||||
info!("Episode {:?} was deleted succesfully.", ep.local_uri());
|
.ok();
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@ -186,10 +186,12 @@ impl App {
|
|||||||
Ok(Action::RefreshEpisodesView) => content.update_episode_view(),
|
Ok(Action::RefreshEpisodesView) => content.update_episode_view(),
|
||||||
Ok(Action::RefreshEpisodesViewBGR) => content.update_episode_view_if_baground(),
|
Ok(Action::RefreshEpisodesViewBGR) => content.update_episode_view_if_baground(),
|
||||||
Ok(Action::ReplaceWidget(pd)) => {
|
Ok(Action::ReplaceWidget(pd)) => {
|
||||||
if let Err(err) = content.get_shows().replace_widget(pd) {
|
content
|
||||||
error!("Something went wrong while trying to update the ShowWidget.");
|
.get_shows()
|
||||||
error!("Error: {}", err);
|
.replace_widget(pd.clone())
|
||||||
}
|
.map_err(|err| error!("Failed to update ShowWidget: {}", err))
|
||||||
|
.map_err(|_| error!("Failed ot update ShowWidget {}", pd.title()))
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
Ok(Action::ShowWidgetAnimated) => content.get_shows().switch_widget_animated(),
|
Ok(Action::ShowWidgetAnimated) => content.get_shows().switch_widget_animated(),
|
||||||
Ok(Action::ShowShowsAnimated) => content.get_shows().switch_podcasts_animated(),
|
Ok(Action::ShowShowsAnimated) => content.get_shows().switch_podcasts_animated(),
|
||||||
@ -200,9 +202,9 @@ impl App {
|
|||||||
Ok(Action::MarkAllPlayerNotification(pd)) => {
|
Ok(Action::MarkAllPlayerNotification(pd)) => {
|
||||||
let id = pd.id();
|
let id = pd.id();
|
||||||
let callback = clone!(sender => move || {
|
let callback = clone!(sender => move || {
|
||||||
if let Err(err) = mark_all_watched(&pd, sender.clone()) {
|
mark_all_watched(&pd, sender.clone())
|
||||||
error!("Something went horribly wrong with the notif callback: {}", err);
|
.map_err(|err| error!("Notif Callback Error: {}", err))
|
||||||
}
|
.ok();
|
||||||
glib::Continue(false)
|
glib::Continue(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -219,23 +221,23 @@ impl App {
|
|||||||
Ok(Action::RemoveShow(pd)) => {
|
Ok(Action::RemoveShow(pd)) => {
|
||||||
let text = format!("Unsubscribed from {}", pd.title());
|
let text = format!("Unsubscribed from {}", pd.title());
|
||||||
|
|
||||||
if let Err(err) = utils::ignore_show(pd.id()) {
|
utils::ignore_show(pd.id())
|
||||||
error!("Could not insert {} to the ignore list.", pd.title());
|
.map_err(|err| error!("Error: {}", err))
|
||||||
error!("Error: {}", err);
|
.map_err(|_| error!("Could not insert {} to the ignore list.", pd.title()))
|
||||||
}
|
.ok();
|
||||||
|
|
||||||
let callback = clone!(pd => move || {
|
let callback = clone!(pd => move || {
|
||||||
if let Err(err) = utils::uningore_show(pd.id()) {
|
utils::uningore_show(pd.id())
|
||||||
error!("Could not remove {} from the ignore list.", pd.title());
|
.map_err(|err| error!("Error: {}", err))
|
||||||
error!("Error: {}", err);
|
.map_err(|_| error!("Could not remove {} from the ignore list.", pd.title()))
|
||||||
}
|
.ok();
|
||||||
|
|
||||||
// Spawn a thread so it won't block the ui.
|
// Spawn a thread so it won't block the ui.
|
||||||
rayon::spawn(clone!(pd => move || {
|
rayon::spawn(clone!(pd => move || {
|
||||||
if let Err(err) = delete_show(&pd) {
|
delete_show(&pd)
|
||||||
error!("Something went wrong trying to remove {}", pd.title());
|
.map_err(|err| error!("Error: {}", err))
|
||||||
error!("Error: {}", err);
|
.map_err(|_| error!("Failed to delete {}", pd.title()))
|
||||||
}
|
.ok();
|
||||||
}));
|
}));
|
||||||
glib::Continue(false)
|
glib::Continue(false)
|
||||||
});
|
});
|
||||||
@ -249,9 +251,7 @@ impl App {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let undo_callback = move || {
|
let undo_callback = move || {
|
||||||
if let Err(err) = undo_wrap() {
|
undo_wrap().map_err(|err| error!("{}", err)).ok();
|
||||||
error!("{}", err)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let notif = InAppNotification::new(text, callback, undo_callback);
|
let notif = InAppNotification::new(text, callback, undo_callback);
|
||||||
|
|||||||
@ -76,15 +76,15 @@ impl Header {
|
|||||||
self.switch.set_stack(&content.get_stack());
|
self.switch.set_stack(&content.get_stack());
|
||||||
|
|
||||||
new_url.connect_changed(clone!(add_button => move |url| {
|
new_url.connect_changed(clone!(add_button => move |url| {
|
||||||
if let Err(err) = on_url_change(url, &result_label, &add_button) {
|
on_url_change(url, &result_label, &add_button)
|
||||||
error!("Error: {}", err);
|
.map_err(|err| error!("Error: {}", err))
|
||||||
}
|
.ok();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
add_button.connect_clicked(clone!(add_popover, new_url, sender => move |_| {
|
add_button.connect_clicked(clone!(add_popover, new_url, sender => move |_| {
|
||||||
if let Err(err) = on_add_bttn_clicked(&new_url, sender.clone()) {
|
on_add_bttn_clicked(&new_url, sender.clone())
|
||||||
error!("Error: {}", err);
|
.map_err(|err| error!("Error: {}", err))
|
||||||
}
|
.ok();
|
||||||
add_popover.hide();
|
add_popover.hide();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -115,9 +115,9 @@ impl Header {
|
|||||||
add_toggle.show();
|
add_toggle.show();
|
||||||
back.hide();
|
back.hide();
|
||||||
show_title.hide();
|
show_title.hide();
|
||||||
if let Err(err) = sender.send(Action::ShowShowsAnimated) {
|
sender.send(Action::ShowShowsAnimated)
|
||||||
error!("Action channel blew up: {}", err);
|
.map_err(|err| error!("Action Sender: {}", err))
|
||||||
}
|
.ok();
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,10 +92,9 @@ pub fn add(id: i32, directory: String, sender: Sender<Action>) -> Result<(), Err
|
|||||||
let id = episode.rowid();
|
let id = episode.rowid();
|
||||||
let pid = episode.podcast_id();
|
let pid = episode.podcast_id();
|
||||||
|
|
||||||
if let Err(err) = get_episode(&mut episode.into(), directory.as_str(), Some(prog)) {
|
get_episode(&mut episode.into(), directory.as_str(), Some(prog))
|
||||||
error!("Error while trying to download an episode");
|
.map_err(|err| error!("Download Failed: {}", err))
|
||||||
error!("Error: {}", err);
|
.ok();
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(mut m) = ACTIVE_DOWNLOADS.write() {
|
if let Ok(mut m) = ACTIVE_DOWNLOADS.write() {
|
||||||
let foo = m.remove(&id);
|
let foo = m.remove(&id);
|
||||||
|
|||||||
@ -43,10 +43,10 @@ impl Content {
|
|||||||
|
|
||||||
// TODO: Maybe propagate the error?
|
// TODO: Maybe propagate the error?
|
||||||
pub fn update_episode_view(&self) {
|
pub fn update_episode_view(&self) {
|
||||||
if let Err(err) = self.episodes.update() {
|
self.episodes
|
||||||
error!("Something went wrong while trying to update the episode view.");
|
.update()
|
||||||
error!("Error: {}", err);
|
.map_err(|err| error!("Failed to update EpisodeView: {}", err))
|
||||||
}
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_episode_view_if_baground(&self) {
|
pub fn update_episode_view_if_baground(&self) {
|
||||||
@ -56,24 +56,24 @@ impl Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_shows_view(&self) {
|
pub fn update_shows_view(&self) {
|
||||||
if let Err(err) = self.shows.update_podcasts() {
|
self.shows
|
||||||
error!("Something went wrong while trying to update the ShowsView.");
|
.update_podcasts()
|
||||||
error!("Error: {}", err);
|
.map_err(|err| error!("Failed to update ShowsView: {}", err))
|
||||||
}
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_widget(&self) {
|
pub fn update_widget(&self) {
|
||||||
if let Err(err) = self.shows.update_widget() {
|
self.shows
|
||||||
error!("Something went wrong while trying to update the Show Widget.");
|
.update_widget()
|
||||||
error!("Error: {}", err);
|
.map_err(|err| error!("Failed to update ShowsWidget: {}", err))
|
||||||
}
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_widget_if_same(&self, pid: i32) {
|
pub fn update_widget_if_same(&self, pid: i32) {
|
||||||
if let Err(err) = self.shows.update_widget_if_same(pid) {
|
self.shows
|
||||||
error!("Something went wrong while trying to update the Show Widget.");
|
.update_widget_if_same(pid)
|
||||||
error!("Error: {}", err);
|
.map_err(|err| error!("Failed to update ShowsWidget: {}", err))
|
||||||
}
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_widget_if_visible(&self) {
|
pub fn update_widget_if_visible(&self) {
|
||||||
|
|||||||
@ -106,19 +106,18 @@ pub fn get_ignored_shows() -> Result<Vec<i32>, Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn cleanup(cleanup_date: DateTime<Utc>) {
|
pub fn cleanup(cleanup_date: DateTime<Utc>) {
|
||||||
if let Err(err) = checkup(cleanup_date) {
|
checkup(cleanup_date)
|
||||||
error!("Check up failed: {}", err);
|
.map_err(|err| error!("Check up failed: {}", err))
|
||||||
}
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn refresh<S>(source: Option<S>, sender: Sender<Action>)
|
pub fn refresh<S>(source: Option<S>, sender: Sender<Action>)
|
||||||
where
|
where
|
||||||
S: IntoIterator<Item = Source> + Send + 'static,
|
S: IntoIterator<Item = Source> + Send + 'static,
|
||||||
{
|
{
|
||||||
if let Err(err) = refresh_feed(source, sender) {
|
refresh_feed(source, sender)
|
||||||
error!("An error occured while trying to update the feeds.");
|
.map_err(|err| error!("Failed to update feeds: {}", err))
|
||||||
error!("Error: {}", err);
|
.ok();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_refresh_interval(settings: &Settings) -> Duration {
|
pub fn get_refresh_interval(settings: &Settings) -> Duration {
|
||||||
|
|||||||
@ -220,9 +220,9 @@ impl EpisodesViewWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init(&self, podcast_id: i32) {
|
fn init(&self, podcast_id: i32) {
|
||||||
if let Err(err) = self.set_cover(podcast_id) {
|
self.set_cover(podcast_id)
|
||||||
error!("Failed to set a cover: {}", err)
|
.map_err(|err| error!("Failed to set a cover: {}", err))
|
||||||
}
|
.ok();
|
||||||
|
|
||||||
self.container.pack_start(&self.episode, true, true, 6);
|
self.container.pack_start(&self.episode, true, true, 6);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,12 +42,9 @@ impl ShowsPopulated {
|
|||||||
|
|
||||||
pub fn init(&self, sender: Sender<Action>) -> Result<(), Error> {
|
pub fn init(&self, sender: Sender<Action>) -> Result<(), Error> {
|
||||||
self.flowbox.connect_child_activated(move |_, child| {
|
self.flowbox.connect_child_activated(move |_, child| {
|
||||||
if let Err(err) = on_child_activate(child, sender.clone()) {
|
on_child_activate(child, sender.clone())
|
||||||
error!(
|
.map_err(|err| error!("Error along flowbox child activation: {}", err))
|
||||||
"Something went wrong during flowbox child activation: {}.",
|
.ok();
|
||||||
err
|
|
||||||
)
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
// Populate the flowbox with the Podcasts.
|
// Populate the flowbox with the Podcasts.
|
||||||
self.populate_flowbox()
|
self.populate_flowbox()
|
||||||
@ -126,10 +123,9 @@ impl ShowsChild {
|
|||||||
self.container.set_tooltip_text(pd.title());
|
self.container.set_tooltip_text(pd.title());
|
||||||
WidgetExt::set_name(&self.child, &pd.id().to_string());
|
WidgetExt::set_name(&self.child, &pd.id().to_string());
|
||||||
|
|
||||||
let pd = Arc::new(pd.into());
|
self.set_cover(Arc::new(pd.into()))
|
||||||
if let Err(err) = self.set_cover(pd) {
|
.map_err(|err| error!("Failed to set a cover: {}", err))
|
||||||
error!("Failed to set a cover: {}", err)
|
.ok();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_cover(&self, pd: Arc<PodcastCoverQuery>) -> Result<(), Error> {
|
fn set_cover(&self, pd: Arc<PodcastCoverQuery>) -> Result<(), Error> {
|
||||||
|
|||||||
@ -97,10 +97,10 @@ impl EpisodeWidget {
|
|||||||
self.set_duration(episode.duration());
|
self.set_duration(episode.duration());
|
||||||
|
|
||||||
// Determine what the state of the media widgets should be.
|
// Determine what the state of the media widgets should be.
|
||||||
if let Err(err) = determine_media_state(self.media.clone(), &episode) {
|
determine_media_state(self.media.clone(), &episode)
|
||||||
error!("Something went wrong determining the Media State.");
|
.map_err(|err| error!("Error: {}", err))
|
||||||
error!("Error: {}", err);
|
.map_err(|_| error!("Could not determine Media State"))
|
||||||
}
|
.ok();
|
||||||
|
|
||||||
let episode = Arc::new(Mutex::new(episode));
|
let episode = Arc::new(Mutex::new(episode));
|
||||||
self.connect_buttons(episode, sender);
|
self.connect_buttons(episode, sender);
|
||||||
@ -111,9 +111,9 @@ impl EpisodeWidget {
|
|||||||
if let Ok(media) = self.media.lock() {
|
if let Ok(media) = self.media.lock() {
|
||||||
media.play_connect_clicked(clone!(episode, sender => move |_| {
|
media.play_connect_clicked(clone!(episode, sender => move |_| {
|
||||||
if let Ok(mut ep) = episode.lock() {
|
if let Ok(mut ep) = episode.lock() {
|
||||||
if let Err(err) = on_play_bttn_clicked(&mut ep, title.clone(), sender.clone()){
|
on_play_bttn_clicked(&mut ep, title.clone(), sender.clone())
|
||||||
error!("Error: {}", err);
|
.map_err(|err| error!("Error: {}", err))
|
||||||
};
|
.ok();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -122,16 +122,14 @@ impl EpisodeWidget {
|
|||||||
// Make the button insensitive so it won't be pressed twice
|
// Make the button insensitive so it won't be pressed twice
|
||||||
dl.set_sensitive(false);
|
dl.set_sensitive(false);
|
||||||
if let Ok(ep) = episode.lock() {
|
if let Ok(ep) = episode.lock() {
|
||||||
if let Err(err) = on_download_clicked(&ep, sender.clone()) {
|
on_download_clicked(&ep, sender.clone())
|
||||||
error!("Download failed to start.");
|
.and_then(|_| {
|
||||||
error!("Error: {}", err);
|
info!("Donwload started succesfully.");
|
||||||
} else {
|
determine_media_state(media_machine.clone(), &ep)
|
||||||
info!("Donwload started succesfully.");
|
})
|
||||||
if let Err(err) = determine_media_state(media_machine.clone(), &ep) {
|
.map_err(|err| error!("Error: {}", err))
|
||||||
error!("Something went wrong determining the Media State.");
|
.map_err(|_| error!("Could not determine Media State"))
|
||||||
error!("Error: {}", err);
|
.ok();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore sensitivity after operations above complete
|
// Restore sensitivity after operations above complete
|
||||||
|
|||||||
@ -74,18 +74,18 @@ impl ShowWidget {
|
|||||||
self.setup_listbox(pd.clone(), sender.clone());
|
self.setup_listbox(pd.clone(), sender.clone());
|
||||||
self.set_description(pd.description());
|
self.set_description(pd.description());
|
||||||
|
|
||||||
if let Err(err) = self.set_cover(pd.clone()) {
|
self.set_cover(pd.clone())
|
||||||
error!("Failed to set a cover: {}", err)
|
.map_err(|err| error!("Failed to set a cover: {}", err))
|
||||||
}
|
.ok();
|
||||||
|
|
||||||
let link = pd.link().to_owned();
|
let link = pd.link().to_owned();
|
||||||
self.link.set_tooltip_text(Some(link.as_str()));
|
self.link.set_tooltip_text(Some(link.as_str()));
|
||||||
self.link.connect_clicked(move |_| {
|
self.link.connect_clicked(move |_| {
|
||||||
info!("Opening link: {}", &link);
|
info!("Opening link: {}", &link);
|
||||||
if let Err(err) = open::that(&link) {
|
open::that(&link)
|
||||||
error!("Failed to open link: {}", &link);
|
.map_err(|err| error!("Error: {}", err))
|
||||||
error!("Error: {}", err);
|
.map_err(|_| error!("Failed open link: {}", &link))
|
||||||
}
|
.ok();
|
||||||
});
|
});
|
||||||
|
|
||||||
let show_menu: gtk::Popover = builder.get_object("show_menu").unwrap();
|
let show_menu: gtk::Popover = builder.get_object("show_menu").unwrap();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user