From f11dd18536e7c4adb119ee3b4c4875cca661e7e2 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 1 Nov 2018 09:34:24 -0700 Subject: [PATCH] Be resilient to malformed ephemeral.json --- app/base_config.js | 5 +++-- app/ephemeral_config.js | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/base_config.js b/app/base_config.js index 31f752cf29..be6096ec3e 100644 --- a/app/base_config.js +++ b/app/base_config.js @@ -8,7 +8,8 @@ module.exports = { start, }; -function start(name, targetPath) { +function start(name, targetPath, options = {}) { + const { allowMalformedOnStartup } = options; let cachedValue = null; try { @@ -23,7 +24,7 @@ function start(name, targetPath) { cachedValue = Object.create(null); } } catch (error) { - if (error.code !== 'ENOENT') { + if (!allowMalformedOnStartup && error.code !== 'ENOENT') { throw error; } diff --git a/app/ephemeral_config.js b/app/ephemeral_config.js index b2b91cb5a1..84b498743f 100644 --- a/app/ephemeral_config.js +++ b/app/ephemeral_config.js @@ -7,6 +7,8 @@ const { start } = require('./base_config'); const userDataPath = app.getPath('userData'); const targetPath = path.join(userDataPath, 'ephemeral.json'); -const ephemeralConfig = start('ephemeral', targetPath); +const ephemeralConfig = start('ephemeral', targetPath, { + allowMalformedOnStartup: true, +}); module.exports = ephemeralConfig;