From 7b1a4b1ae7867b7b364a44572f1c01dbf0f0416a Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 23 Mar 2021 10:59:15 +0100 Subject: [PATCH] Recover from corrupted roster cache --- www/common/outer/roster.js | 8 ++++++++ www/common/outer/team.js | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/www/common/outer/roster.js b/www/common/outer/roster.js index 28c181079..11024c609 100644 --- a/www/common/outer/roster.js +++ b/www/common/outer/roster.js @@ -573,6 +573,14 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto, Feedback) var ready = false; var onCacheReady = function () { if (!config.onCacheReady) { return; } + var state = ref.state; + if (!Object.keys(state.members || {}).length) { + // No member, corrupted cache + try { + ref.internal.cpNetflux.resetCache(); + } catch (e) { console.error(e); } + return void config.onCacheReady({error: "CORRUPTED"}); + } config.onCacheReady(roster); }; var onReady = function (info) { diff --git a/www/common/outer/team.js b/www/common/outer/team.js index 31785e26b..742836fb9 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -547,6 +547,14 @@ define([ store: ctx.store, lastKnownHash: rosterData.lastKnownHash, onCacheReady: function (_roster) { + if (!cache) { return; } + console.error('Corrupted roster cache, cant load this team offline', teamData); + if (_roster && _roster.error === "CORRUPTED") { + if (lm && typeof(lm.stop) === "function") { lm.stop(); } + waitFor.abort(); + cb({error: 'CACHE_CORRUPTED_ROSTER'}); + return; + } roster = _roster; cacheRdy.roster = true; cacheRdy.check();