Commit 530074e1 authored by Georgiana Piscoi's avatar Georgiana Piscoi

Refs #78 - Try to use data from storage.local if connecting to IndexedDB fails

parent 22324378
Pipeline #81387844 passed with stages
in 11 minutes and 9 seconds
......@@ -37,7 +37,7 @@ function openDB()
return resolve(event.currentTarget.result);
};
req.onerror = reject;
req.onerror = event => reject(event.currentTarget.error);
req.onupgradeneeded = event =>
{
......@@ -177,6 +177,27 @@ function deleteFile(fileName, dbInstance)
});
}
// In some cases Microsoft Edge has issues with IndexedDB and any operation,
// returns "UnknownError".
// We perform this check only on startup as the backup mechanism
// can handle the writes.
function handleIndexedDBError(error)
{
if (error.type != "NoSuchFile")
{
const {IndexedDBBackup} = require("./indexedDBBackup");
// If the devtools are not open when logging an object,
// the printed message is just the string [object Object],
// so we workaround it by using error.toString.
console.error("IndexedDB error:", error.toString());
return IndexedDBBackup.getBackupData();
}
throw error;
}
exports.IO =
{
/**
......@@ -207,6 +228,7 @@ exports.IO =
readFromFile(fileName, listener)
{
return db.then(dbInstance => getFile(fileName, dbInstance))
.catch(handleIndexedDBError)
.then(entry =>
{
for (let line of entry.content)
......@@ -225,6 +247,7 @@ exports.IO =
statFile(fileName)
{
return db.then(dbInstance => getFile(fileName, dbInstance))
.catch(handleIndexedDBError)
.then(entry =>
{
return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment