From 7ddeacc62913d9c521590379785db0aa95aa0f2b Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 6 Jan 2021 15:56:58 +0530 Subject: [PATCH] serialize localForage errors and add a safety net --- www/common/outer/cache-store.js | 8 ++++---- www/common/sframe-common-outer.js | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/www/common/outer/cache-store.js b/www/common/outer/cache-store.js index 7a0a50209..a7b1bd3d7 100644 --- a/www/common/outer/cache-store.js +++ b/www/common/outer/cache-store.js @@ -32,7 +32,7 @@ define([ if (!allowed) { return void cb('NOCACHE'); } cache.getItem(id, function (err, obj) { if (err || !obj || !obj.c) { - return void cb(err || 'EINVAL'); + return void cb(Util.serializeError(err || 'EINVAL')); } cb(null, obj.c); obj.t = +new Date(); @@ -50,7 +50,7 @@ define([ c: u8, t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set) }, function (err) { - cb(err); + cb(Util.serializeError(err)); }); }); }; @@ -64,7 +64,7 @@ define([ if (!allowed) { return void cb('NOCACHE'); } cache.getItem(id, function (err, obj) { if (err || !obj || !Array.isArray(obj.c)) { - return void cb(err || 'EINVAL'); + return void cb(Util.serializeError(err || 'EINVAL')); } cb(null, obj); obj.t = +new Date(); @@ -108,7 +108,7 @@ define([ c: val, t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set) }, function (err) { - if (err) { onError(err); } + if (err) { onError(Util.serializeError(err)); } }); }, 50); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index ca760efb8..15c192d16 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -157,7 +157,24 @@ define([ var msgEv = _Util.mkEvent(); var iframe = $('#sbox-iframe')[0].contentWindow; var postMsg = function (data) { - iframe.postMessage(data, '*'); + try { + iframe.postMessage(data, '*'); + } catch (err) { + console.error(err); + console.error(data); + if (data && data.error && data.error instanceof Error) { + data.error = Util.serializeError(data.error); + try { + iframe.postMessage(data, '*'); + } catch (err2) { + // XXX + console.error("impossible serialization"); + throw err2; + } + } else { + throw err; + } + } }; var whenReady = waitFor(function (msg) { if (msg.source !== iframe) { return; }