Browse Source

Properly recover from error opening file

At first I thought the `map_err` would be the right way to solve this,
but actually it didn't do what I expected.
master
Julio Biason 4 years ago
parent
commit
a1bf236a83
  1. 6
      src/storage/org.rs

6
src/storage/org.rs

@ -52,7 +52,7 @@ impl Storage for Org {
.write(true) .write(true)
.append(true) .append(true)
.open(&self.file) .open(&self.file)
.map_err(|_| { .unwrap_or_else(|_| {
// Let's assume here that the problem is that the file doesn't exist. // Let's assume here that the problem is that the file doesn't exist.
log::debug!( log::debug!(
"Creating {filename}", "Creating {filename}",
@ -68,8 +68,8 @@ impl Storage for Org {
fp.write_all(text.as_bytes()).unwrap(); fp.write_all(text.as_bytes()).unwrap();
fp fp
}) })
}) .unwrap()
.unwrap(); });
fp.write_all( fp.write_all(
format!( format!(
"* {user}/{id}\n {message}\n", "* {user}/{id}\n {message}\n",

Loading…
Cancel
Save