Be resilient to malformed ephemeral.json

pull/27/head^2
Scott Nonnenberg 7 years ago
parent 41dd78c073
commit f11dd18536

@ -8,7 +8,8 @@ module.exports = {
start, start,
}; };
function start(name, targetPath) { function start(name, targetPath, options = {}) {
const { allowMalformedOnStartup } = options;
let cachedValue = null; let cachedValue = null;
try { try {
@ -23,7 +24,7 @@ function start(name, targetPath) {
cachedValue = Object.create(null); cachedValue = Object.create(null);
} }
} catch (error) { } catch (error) {
if (error.code !== 'ENOENT') { if (!allowMalformedOnStartup && error.code !== 'ENOENT') {
throw error; throw error;
} }

@ -7,6 +7,8 @@ const { start } = require('./base_config');
const userDataPath = app.getPath('userData'); const userDataPath = app.getPath('userData');
const targetPath = path.join(userDataPath, 'ephemeral.json'); const targetPath = path.join(userDataPath, 'ephemeral.json');
const ephemeralConfig = start('ephemeral', targetPath); const ephemeralConfig = start('ephemeral', targetPath, {
allowMalformedOnStartup: true,
});
module.exports = ephemeralConfig; module.exports = ephemeralConfig;

Loading…
Cancel
Save