From b5d5d1c3932467f8b5206522f0702b62825db6cb Mon Sep 17 00:00:00 2001 From: Skye J Date: Tue, 30 May 2023 17:54:46 -0400 Subject: [PATCH 1/2] Fixed error where an invalid event would cause the entire application to halt, this just ignores it. --- src/Cache.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index 44f2ecb0..536a1f32 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -34,6 +34,7 @@ #include "UserSettingsPage.h" #include "Utils.h" #include "encryption/Olm.h" +#include //! Should be changed when a breaking change occurs in the cache format. //! This will reset client's data. @@ -1848,6 +1849,7 @@ isMessage(const mtx::events::RoomEvent &) // } } + void Cache::saveState(const mtx::responses::Sync &res) { @@ -1876,10 +1878,17 @@ Cache::saveState(const mtx::responses::Sync &res) } auto j = nlohmann::json(event); - accountDataDb.put(txn, j["type"].get(), j.dump()); + try { + accountDataDb.put(txn, j["type"].get(), j.dump()); + } + catch (const lmdb::error &e) { + nhlog::db()->warn("failed to save state after sync: {}, skipping event", e.what()); + return; + } }, ev); - } + } + auto userKeyCacheDb = getUserKeysDb(txn); From 7fb8fac6ca5043e5f7a31dd8f9e57b5e07f2921a Mon Sep 17 00:00:00 2001 From: Skye J Date: Tue, 30 May 2023 17:59:40 -0400 Subject: [PATCH 2/2] Made style consistent with clang-format --- src/Cache.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Cache.cpp b/src/Cache.cpp index 536a1f32..a2fecd3e 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -1849,7 +1849,6 @@ isMessage(const mtx::events::RoomEvent &) // } } - void Cache::saveState(const mtx::responses::Sync &res) { @@ -1879,16 +1878,15 @@ Cache::saveState(const mtx::responses::Sync &res) auto j = nlohmann::json(event); try { - accountDataDb.put(txn, j["type"].get(), j.dump()); - } - catch (const lmdb::error &e) { - nhlog::db()->warn("failed to save state after sync: {}, skipping event", e.what()); - return; + accountDataDb.put(txn, j["type"].get(), j.dump()); + } catch (const lmdb::error &e) { + nhlog::db()->warn("failed to save state after sync: {}, skipping event", + e.what()); + return; } }, ev); - } - + } auto userKeyCacheDb = getUserKeysDb(txn);