serialize localForage errors and add a safety net

pull/1/head
ansuz 4 years ago
parent 662629185d
commit 7ddeacc629

@ -32,7 +32,7 @@ define([
if (!allowed) { return void cb('NOCACHE'); } if (!allowed) { return void cb('NOCACHE'); }
cache.getItem(id, function (err, obj) { cache.getItem(id, function (err, obj) {
if (err || !obj || !obj.c) { if (err || !obj || !obj.c) {
return void cb(err || 'EINVAL'); return void cb(Util.serializeError(err || 'EINVAL'));
} }
cb(null, obj.c); cb(null, obj.c);
obj.t = +new Date(); obj.t = +new Date();
@ -50,7 +50,7 @@ define([
c: u8, c: u8,
t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set) t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set)
}, function (err) { }, function (err) {
cb(err); cb(Util.serializeError(err));
}); });
}); });
}; };
@ -64,7 +64,7 @@ define([
if (!allowed) { return void cb('NOCACHE'); } if (!allowed) { return void cb('NOCACHE'); }
cache.getItem(id, function (err, obj) { cache.getItem(id, function (err, obj) {
if (err || !obj || !Array.isArray(obj.c)) { if (err || !obj || !Array.isArray(obj.c)) {
return void cb(err || 'EINVAL'); return void cb(Util.serializeError(err || 'EINVAL'));
} }
cb(null, obj); cb(null, obj);
obj.t = +new Date(); obj.t = +new Date();
@ -108,7 +108,7 @@ define([
c: val, c: val,
t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set) t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set)
}, function (err) { }, function (err) {
if (err) { onError(err); } if (err) { onError(Util.serializeError(err)); }
}); });
}, 50); }, 50);

@ -157,7 +157,24 @@ define([
var msgEv = _Util.mkEvent(); var msgEv = _Util.mkEvent();
var iframe = $('#sbox-iframe')[0].contentWindow; var iframe = $('#sbox-iframe')[0].contentWindow;
var postMsg = function (data) { var postMsg = function (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, '*'); iframe.postMessage(data, '*');
} catch (err2) {
// XXX
console.error("impossible serialization");
throw err2;
}
} else {
throw err;
}
}
}; };
var whenReady = waitFor(function (msg) { var whenReady = waitFor(function (msg) {
if (msg.source !== iframe) { return; } if (msg.source !== iframe) { return; }

Loading…
Cancel
Save