From 7198cee85e19f020e8e517b4d7f0f60f2bff88f8 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 1 Jul 2022 09:14:17 +0200 Subject: [PATCH] Fix crash on empty user cache stored --- src/Cache.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index 67889543..c9baaf5e 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -4442,11 +4442,15 @@ Cache::markUserKeysOutOfDate(lmdb::txn &txn, std::string_view oldKeys; - UserKeyCache cacheEntry; + UserKeyCache cacheEntry{}; auto res = db.get(txn, user, oldKeys); if (res) { - cacheEntry = nlohmann::json::parse(std::string_view(oldKeys.data(), oldKeys.size())) - .get(); + try { + cacheEntry = nlohmann::json::parse(std::string_view(oldKeys.data(), oldKeys.size())) + .get(); + } catch (std::exception &e) { + nhlog::db()->error("Failed to parse {}: {}", oldKeys, e.what()); + } } cacheEntry.last_changed = sync_token;