From a1bf236a830e62e5c0f3344d8b9a88a0dd5ee959 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 19 Apr 2021 14:20:26 -0300 Subject: [PATCH] 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. --- src/storage/org.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/storage/org.rs b/src/storage/org.rs index 8d0677b..3205ffe 100644 --- a/src/storage/org.rs +++ b/src/storage/org.rs @@ -52,7 +52,7 @@ impl Storage for Org { .write(true) .append(true) .open(&self.file) - .map_err(|_| { + .unwrap_or_else(|_| { // Let's assume here that the problem is that the file doesn't exist. log::debug!( "Creating {filename}", @@ -68,8 +68,8 @@ impl Storage for Org { fp.write_all(text.as_bytes()).unwrap(); fp }) - }) - .unwrap(); + .unwrap() + }); fp.write_all( format!( "* {user}/{id}\n {message}\n",