backend: Replace some errors with warnings

This commit is contained in:
Elias Projahn 2021-02-05 10:25:37 +01:00
parent b9b0b61319
commit 5774075cad
5 changed files with 33 additions and 16 deletions

View file

@ -10,6 +10,7 @@ gio = "0.9.1"
glib = "0.10.3"
gstreamer = "0.16.4"
gstreamer-player = "0.16.3"
log = "0.4.14"
mpris-player = "0.6.0"
musicus_client = { version = "0.1.0", path = "../musicus_client" }
musicus_database = { version = "0.1.0", path = "../musicus_database" }

View file

@ -10,9 +10,6 @@ pub enum Error {
#[error("An error happened using the SecretService.")]
SecretServiceError(#[from] secret_service::Error),
#[error("An error happened in GLib.")]
GlibError(#[from] glib::BoolError),
#[error("A channel was canceled.")]
ChannelError(#[from] futures_channel::oneshot::Canceled),

View file

@ -1,5 +1,6 @@
use futures_channel::mpsc;
use gio::prelude::*;
use log::warn;
use std::cell::RefCell;
use std::path::PathBuf;
use std::rc::Rc;
@ -74,18 +75,24 @@ impl Backend {
}
}
if let Some(data) = Self::load_login_data().await? {
self.client.set_login_data(data);
match Self::load_login_data().await {
Ok(Some(data)) => self.client.set_login_data(data),
Err(err) => warn!("The login data could not be loaded from SecretService. It will not \
be available. Error message: {}", err),
_ => (),
}
Ok(())
}
/// Set the URL of the Musicus server to connect to.
pub fn set_server_url(&self, url: &str) -> Result<()> {
self.settings.set_string("server-url", url)?;
pub fn set_server_url(&self, url: &str) {
if let Err(err) = self.settings.set_string("server-url", url) {
warn!("An error happened while trying to save the server URL to GSettings. Most \
likely it will not be available at the next startup. Error message: {}", err);
}
self.client.set_server_url(url);
Ok(())
}
/// Get the currently set server URL.
@ -94,10 +101,14 @@ impl Backend {
}
/// Set the user credentials to use.
pub async fn set_login_data(&self, data: LoginData) -> Result<()> {
Self::store_login_data(data.clone()).await?;
pub async fn set_login_data(&self, data: LoginData) {
if let Err(err) = Self::store_login_data(data.clone()).await {
warn!("An error happened while trying to store the login data using SecretService. \
This means, that they will not be available at the next startup most likely. \
Error message: {}", err);
}
self.client.set_login_data(data);
Ok(())
}
pub fn cl(&self) -> &Client {

View file

@ -1,6 +1,7 @@
use crate::{Backend, BackendState, Player, Result};
use musicus_database::DbThread;
use gio::prelude::*;
use log::warn;
use std::path::PathBuf;
use std::rc::Rc;
@ -19,8 +20,11 @@ impl Backend {
/// Set the path to the music library folder and start a database thread in the background.
pub async fn set_music_library_path(&self, path: PathBuf) -> Result<()> {
self.settings
.set_string("music-library-path", path.to_str().unwrap())?;
if let Err(err) = self.settings.set_string("music-library-path", path.to_str().unwrap()) {
warn!("The music library path could not be saved using GSettings. It will most likely \
not be available at the next startup. Error message: {}", err);
}
self.set_music_library_path_priv(path).await
}

View file

@ -1,4 +1,4 @@
use crate::{Backend, Result};
use crate::{Backend, Error, Result};
use musicus_client::LoginData;
use futures_channel::oneshot;
use secret_service::{Collection, EncryptionType, SecretService};
@ -32,8 +32,12 @@ impl Backend {
Ok(match item {
Some(item) => {
// TODO: Delete the item when malformed.
let username = item.get_attributes()?.get("username").unwrap().to_owned();
let username = item
.get_attributes()?
.get("username")
.ok_or(Error::Other("Missing username in SecretService attributes."))?
.to_owned();
let password = std::str::from_utf8(&item.get_secret()?)?.to_owned();
Some(LoginData { username, password })