From 99b53f4a55c6957796b345d8f6a5a19ddb3f73d7 Mon Sep 17 00:00:00 2001 From: Milo Todt Date: Sun, 13 Jan 2019 18:21:12 -0800 Subject: [PATCH 1/3] added filter. --- browser/main/lib/dataApi/init.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/browser/main/lib/dataApi/init.js b/browser/main/lib/dataApi/init.js index 7f81e90b..adab0232 100644 --- a/browser/main/lib/dataApi/init.js +++ b/browser/main/lib/dataApi/init.js @@ -4,6 +4,7 @@ const resolveStorageData = require('./resolveStorageData') const resolveStorageNotes = require('./resolveStorageNotes') const consts = require('browser/lib/consts') const path = require('path') +const fs = require('fs') const CSON = require('@rokt33r/season') /** * @return {Object} all storages and notes @@ -19,11 +20,14 @@ const CSON = require('@rokt33r/season') * 2. legacy * 3. empty directory */ + function init () { const fetchStorages = function () { let rawStorages try { rawStorages = JSON.parse(window.localStorage.getItem('storages')) + // Remove storages who's location is inaccesible. + rawStorages = rawStorages.filter(storage => fs.existsSync(storage.path)) if (!_.isArray(rawStorages)) throw new Error('Cached data is not valid.') } catch (e) { console.warn('Failed to parse cached data from localStorage', e) From 8d817066e85f8841036dff8d122694ca27bee5a1 Mon Sep 17 00:00:00 2001 From: Milo Todt Date: Sun, 13 Jan 2019 18:35:24 -0800 Subject: [PATCH 2/3] Added a few more checks in related methods to prevent simular errors --- browser/main/lib/dataApi/init.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/browser/main/lib/dataApi/init.js b/browser/main/lib/dataApi/init.js index adab0232..5149c263 100644 --- a/browser/main/lib/dataApi/init.js +++ b/browser/main/lib/dataApi/init.js @@ -40,6 +40,7 @@ function init () { const fetchNotes = function (storages) { const findNotesFromEachStorage = storages + .filter(storage => fs.existsSync(storage.path)) .map((storage) => { return resolveStorageNotes(storage) .then((notes) => { @@ -54,7 +55,7 @@ function init () { }) } }) - if (unknownCount > 0) { + if (unknownCount > 0 && fs.existsSync(storage.path)) { CSON.writeFileSync(path.join(storage.path, 'boostnote.json'), _.pick(storage, ['folders', 'version'])) } return notes From eea01f10ace4d8393875ede77a868c84ea1a1661 Mon Sep 17 00:00:00 2001 From: Milo Todt Date: Thu, 17 Jan 2019 17:00:07 -0800 Subject: [PATCH 3/3] Added catch for exceptions, removed uneeded duplicate test. --- browser/main/lib/dataApi/init.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/main/lib/dataApi/init.js b/browser/main/lib/dataApi/init.js index 5149c263..0dbcc182 100644 --- a/browser/main/lib/dataApi/init.js +++ b/browser/main/lib/dataApi/init.js @@ -55,8 +55,12 @@ function init () { }) } }) - if (unknownCount > 0 && fs.existsSync(storage.path)) { - CSON.writeFileSync(path.join(storage.path, 'boostnote.json'), _.pick(storage, ['folders', 'version'])) + if (unknownCount > 0) { + try { + CSON.writeFileSync(path.join(storage.path, 'boostnote.json'), _.pick(storage, ['folders', 'version'])) + } catch (e) { + console.log('Error writting boostnote.json: ' + e + ' from init.js') + } } return notes })