Retry fixing the StorageBackend::cause()

This commit is contained in:
Matthias Beyer 2015-11-28 15:43:40 +01:00
parent 366121b6ed
commit 4a6d1a74c0

View file

@ -117,7 +117,7 @@ impl StorageBackend {
debug!("Writing file: {}", path); debug!("Writing file: {}", path);
debug!(" string: {}", string); debug!(" string: {}", string);
FSFile::create(&path).map(|file| { FSFile::create(&path).map(|mut file| {
debug!("Created file at '{}'", path); debug!("Created file at '{}'", path);
file.write_all(&string.clone().into_bytes()) file.write_all(&string.clone().into_bytes())
.map_err(|ioerr| { .map_err(|ioerr| {
@ -127,7 +127,7 @@ impl StorageBackend {
"Could not write out File contents", "Could not write out File contents",
"", None "", None
); );
err.caused_by = Some(&ioerr); err.caused_by = Some(Box::new(ioerr));
err err
}) })
}).map_err(|writeerr| { }).map_err(|writeerr| {
@ -157,7 +157,7 @@ impl StorageBackend {
debug!("Writing file: {}", path); debug!("Writing file: {}", path);
debug!(" string: {}", string); debug!(" string: {}", string);
FSFile::open(&path).map(|file| { FSFile::open(&path).map(|mut file| {
debug!("Open file at '{}'", path); debug!("Open file at '{}'", path);
file.write_all(&string.clone().into_bytes()) file.write_all(&string.clone().into_bytes())
.map_err(|ioerr| { .map_err(|ioerr| {
@ -168,7 +168,7 @@ impl StorageBackend {
"Tried to write contents of this file, though operation did not succeed", "Tried to write contents of this file, though operation did not succeed",
Some(string) Some(string)
); );
err.caused_by = Some(&ioerr); err.caused_by = Some(Box::new(ioerr));
err err
}) })
}).map_err(|writeerr| { }).map_err(|writeerr| {
@ -179,7 +179,7 @@ impl StorageBackend {
"Tried to update contents of this file, though file doesn't exist", "Tried to update contents of this file, though file doesn't exist",
None None
); );
err.caused_by = Some(&writeerr); err.caused_by = Some(Box::new(writeerr));
err err
}).and(Ok(())) }).and(Ok(()))
} }
@ -243,14 +243,14 @@ impl StorageBackend {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct StorageBackendError<'a> { pub struct StorageBackendError {
pub action: String, // The file system action in words pub action: String, // The file system action in words
pub desc: String, // A short description pub desc: String, // A short description
pub data_dump: Option<String>, // Data dump, if any pub data_dump: Option<String>, // Data dump, if any
pub caused_by: Option<Box<Error>>, // caused from this error pub caused_by: Option<Box<Error>>, // caused from this error
} }
impl<'a> StorageBackendError<'a> { impl StorageBackendError {
fn new(action: String, fn new(action: String,
desc : String, desc : String,
data : Option<String>) -> StorageBackendError<'a> data : Option<String>) -> StorageBackendError<'a>
@ -277,7 +277,7 @@ impl<'a> StorageBackendError<'a> {
} }
impl<'a> Error for StorageBackendError<'a> { impl Error for StorageBackendError {
fn description(&self) -> &str { fn description(&self) -> &str {
&self.desc[..] &self.desc[..]
@ -289,7 +289,7 @@ impl<'a> Error for StorageBackendError<'a> {
} }
impl<'a> Display for StorageBackendError<'a> { impl<'a> Display for StorageBackendError {
fn fmt(&self, f: &mut Formatter) -> FMTResult { fn fmt(&self, f: &mut Formatter) -> FMTResult {
write!(f, "StorageBackendError[{}]: {}", write!(f, "StorageBackendError[{}]: {}",
self.action, self.desc) self.action, self.desc)
@ -297,7 +297,9 @@ impl<'a> Display for StorageBackendError<'a> {
} }
fn write_with_parser<'a, HP>(f: &File, p: &Parser<HP>) -> Result<String, StorageBackendError<'a>> { fn write_with_parser<'a, HP>(f: &File, p: &Parser<HP>) -> Result<String, StorageBackendError>
where HP: FileHeaderParser
{
p.write(f.contents()) p.write(f.contents())
.or_else(|err| { .or_else(|err| {
let mut serr = StorageBackendError::build( let mut serr = StorageBackendError::build(
@ -306,7 +308,7 @@ fn write_with_parser<'a, HP>(f: &File, p: &Parser<HP>) -> Result<String, Storage
"Cannot translate internal representation of file contents into on-disk representation", "Cannot translate internal representation of file contents into on-disk representation",
None None
); );
serr.caused_by = Some(&err); serr.caused_by = Some(Box::new(err));
Err(serr) Err(serr)
}) })
} }