Improve error handling
This commit is contained in:
parent
686f5a0f4c
commit
02c60b23ea
@ -174,8 +174,8 @@ macro_rules! result_warn {
|
|||||||
::std::result::Result::Ok(v) => Ok(v),
|
::std::result::Result::Ok(v) => Ok(v),
|
||||||
::std::result::Result::Err(err) => {
|
::std::result::Result::Err(err) => {
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
let warn_string = format!("{}\n\nCause: {}", err.description(),
|
let warn_string = format!("{}{}", err.description(),
|
||||||
err.cause().map(|e| e.description()).unwrap_or(""));
|
err.cause().map(|e| format!("\n\nCause: {}", e.description())).unwrap_or(String::from("")));
|
||||||
warn!("{}", warn_string);
|
warn!("{}", warn_string);
|
||||||
error_dialog!(warn_string.as_str(), $parent);
|
error_dialog!(warn_string.as_str(), $parent);
|
||||||
Err(err)
|
Err(err)
|
||||||
@ -192,8 +192,8 @@ macro_rules! wresult_warn {
|
|||||||
::w_result::WResult::WOk(t, ws) => {
|
::w_result::WResult::WOk(t, ws) => {
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
for w in ws {
|
for w in ws {
|
||||||
let warn_string = format!("{}\n\nCause: {}", w.description(),
|
let warn_string = format!("{}{}", w.description(),
|
||||||
w.cause().map(|e| e.description()).unwrap_or(""));
|
w.cause().map(|e| format!("\n\nCause: {}", e.description())).unwrap_or(String::from("")));
|
||||||
warn!("{}", warn_string);
|
warn!("{}", warn_string);
|
||||||
error_dialog!(warn_string.as_str(), $parent);
|
error_dialog!(warn_string.as_str(), $parent);
|
||||||
}
|
}
|
||||||
@ -223,8 +223,8 @@ macro_rules! unwrap_error {
|
|||||||
::std::result::Result::Ok(v) => v,
|
::std::result::Result::Ok(v) => v,
|
||||||
::std::result::Result::Err(err) => {
|
::std::result::Result::Err(err) => {
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
let err_string = format!("{}\n\nCause: {}", err.description(),
|
let err_string = format!("{}{}", err.description(),
|
||||||
err.cause().map(|e| e.description()).unwrap_or(""));
|
err.cause().map(|e| format!("\n\nCause: {}", e.description())).unwrap_or(String::from("")));
|
||||||
|
|
||||||
error!("{}", err_string);
|
error!("{}", err_string);
|
||||||
error_dialog!(err_string.as_str(), $parent);
|
error_dialog!(err_string.as_str(), $parent);
|
||||||
|
15
src/prefs.rs
15
src/prefs.rs
@ -250,14 +250,21 @@ impl Prefs {
|
|||||||
/// Store the current preferences to the config file.
|
/// Store the current preferences to the config file.
|
||||||
pub fn store_config(&self) -> Result<()> {
|
pub fn store_config(&self) -> Result<()> {
|
||||||
let config_path = get_xdg_dirs().place_config_file("pnmixer.toml")
|
let config_path = get_xdg_dirs().place_config_file("pnmixer.toml")
|
||||||
.from_err()?;
|
.chain_err(|| {
|
||||||
|
format!("Could not create config directory at {:?}",
|
||||||
|
get_xdg_dirs().get_config_home())
|
||||||
|
})?;
|
||||||
|
|
||||||
debug!("Storing config in {:?}", config_path);
|
debug!("Storing config in {:?}", config_path);
|
||||||
|
|
||||||
let mut f = File::create(config_path)
|
let mut f = File::create(config_path.clone())
|
||||||
.chain_err(|| "Could not open/create config file for writing")?;
|
.chain_err(|| format!("Could not open/create config file {:?} for writing",
|
||||||
|
config_path))?;
|
||||||
f.write_all(self.to_str().as_bytes())
|
f.write_all(self.to_str().as_bytes())
|
||||||
.chain_err(|| "Could not write to config file")?;
|
.chain_err(|| {
|
||||||
|
format!("Could not write to config file {:?}",
|
||||||
|
config_path)
|
||||||
|
})?;
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user