From 47284867f9893af1c64393dbabeb30238afb5e4d Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 24 Jun 2021 15:28:24 +1000 Subject: [PATCH] report object type where json decode fails --- rslib/src/storage/deck/mod.rs | 4 +++- rslib/src/storage/deckconfig/mod.rs | 2 +- rslib/src/storage/notetype/mod.rs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rslib/src/storage/deck/mod.rs b/rslib/src/storage/deck/mod.rs index b8380e381..afbf768a7 100644 --- a/rslib/src/storage/deck/mod.rs +++ b/rslib/src/storage/deck/mod.rs @@ -361,7 +361,9 @@ impl SqliteStorage { pub(crate) fn upgrade_decks_to_schema15(&self, server: bool) -> Result<()> { let usn = self.usn(server)?; - let decks = self.get_schema11_decks()?; + let decks = self + .get_schema11_decks() + .map_err(|e| AnkiError::JsonError(format!("decoding decks: {}", e)))?; let mut names = HashSet::new(); for (_id, deck) in decks { let oldname = deck.name().to_string(); diff --git a/rslib/src/storage/deckconfig/mod.rs b/rslib/src/storage/deckconfig/mod.rs index 3d1895982..66d61f43c 100644 --- a/rslib/src/storage/deckconfig/mod.rs +++ b/rslib/src/storage/deckconfig/mod.rs @@ -160,7 +160,7 @@ impl SqliteStorage { let conf: Value = serde_json::from_str(text)?; serde_json::from_value(conf) }) - .map_err(Into::into) + .map_err(|e| AnkiError::JsonError(format!("decoding deck config: {}", e))) })?; for (id, mut conf) in conf.into_iter() { // buggy clients may have failed to set inner id to match hash key diff --git a/rslib/src/storage/notetype/mod.rs b/rslib/src/storage/notetype/mod.rs index 24ce24de2..558ded5b5 100644 --- a/rslib/src/storage/notetype/mod.rs +++ b/rslib/src/storage/notetype/mod.rs @@ -302,7 +302,9 @@ impl SqliteStorage { } pub(crate) fn upgrade_notetypes_to_schema15(&self) -> Result<()> { - let nts = self.get_schema11_notetypes()?; + let nts = self + .get_schema11_notetypes() + .map_err(|e| AnkiError::JsonError(format!("decoding models: {}", e)))?; let mut names = HashSet::new(); for (mut ntid, nt) in nts { let mut nt = Notetype::from(nt);