From d4b80a0c5c9c434f5ea511b5f33ca159d28216aa Mon Sep 17 00:00:00 2001 From: Glenn Griffin Date: Wed, 20 Nov 2019 11:19:48 -0800 Subject: [PATCH] Fix a bug in refactoring the storage layer. Attempting to load from disk when the file does not exist should not return an error and should continue with an empty set of tokens. --- src/storage.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/storage.rs b/src/storage.rs index 92acfc2..35e123a 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -227,7 +227,12 @@ pub(crate) struct DiskStorage { impl DiskStorage { pub(crate) async fn new(path: PathBuf) -> Result { - let tokens = JSONTokens::load_from_file(&path).await?; + let tokens = match JSONTokens::load_from_file(&path).await { + Ok(tokens) => tokens, + Err(e) if e.kind() == io::ErrorKind::NotFound => JSONTokens::new(), + Err(e) => return Err(e), + }; + // Writing to disk will happen in a separate task. This means in the // common case returning a token to the user will not be required to // wait for disk i/o. We communicate with a dedicated writer task via a