Improve error handling

This commit is contained in:
Julian Ospald 2017-07-16 23:28:21 +02:00
parent 686f5a0f4c
commit 02c60b23ea
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 17 additions and 10 deletions

View File

@ -174,8 +174,8 @@ macro_rules! result_warn {
::std::result::Result::Ok(v) => Ok(v),
::std::result::Result::Err(err) => {
use std::error::Error;
let warn_string = format!("{}\n\nCause: {}", err.description(),
err.cause().map(|e| e.description()).unwrap_or(""));
let warn_string = format!("{}{}", err.description(),
err.cause().map(|e| format!("\n\nCause: {}", e.description())).unwrap_or(String::from("")));
warn!("{}", warn_string);
error_dialog!(warn_string.as_str(), $parent);
Err(err)
@ -192,8 +192,8 @@ macro_rules! wresult_warn {
::w_result::WResult::WOk(t, ws) => {
use std::error::Error;
for w in ws {
let warn_string = format!("{}\n\nCause: {}", w.description(),
w.cause().map(|e| e.description()).unwrap_or(""));
let warn_string = format!("{}{}", w.description(),
w.cause().map(|e| format!("\n\nCause: {}", e.description())).unwrap_or(String::from("")));
warn!("{}", warn_string);
error_dialog!(warn_string.as_str(), $parent);
}
@ -223,8 +223,8 @@ macro_rules! unwrap_error {
::std::result::Result::Ok(v) => v,
::std::result::Result::Err(err) => {
use std::error::Error;
let err_string = format!("{}\n\nCause: {}", err.description(),
err.cause().map(|e| e.description()).unwrap_or(""));
let err_string = format!("{}{}", err.description(),
err.cause().map(|e| format!("\n\nCause: {}", e.description())).unwrap_or(String::from("")));
error!("{}", err_string);
error_dialog!(err_string.as_str(), $parent);

View File

@ -250,14 +250,21 @@ impl Prefs {
/// Store the current preferences to the config file.
pub fn store_config(&self) -> Result<()> {
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);
let mut f = File::create(config_path)
.chain_err(|| "Could not open/create config file for writing")?;
let mut f = File::create(config_path.clone())
.chain_err(|| format!("Could not open/create config file {:?} for writing",
config_path))?;
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(());
}