A local-first personal finance app
Report parse issues for config.json in default location (#167)
Jakub Kuczysd02e1b364029
diff --git a/src/load-config.js b/src/load-config.jsindex 429ed3d188..d72e09e3a7 100644--- a/src/load-config.js+++ b/src/load-config.js@@ -6,19 +6,24 @@ const projectRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)));export const sqlDir = path.join(projectRoot, 'src', 'sql');let defaultDataDir = fs.existsSync('/data') ? '/data' : projectRoot;-function parseJSON(path) {- return JSON.parse(fs.readFileSync(path, 'utf8'));+function parseJSON(path, allowMissing = false) {+ let text;+ try {+ text = fs.readFileSync(path, 'utf8');+ } catch (e) {+ if (allowMissing) {+ return {};+ }+ throw e;+ }+ return JSON.parse(text);}let userConfig;if (process.env.ACTUAL_CONFIG_PATH) {userConfig = parseJSON(process.env.ACTUAL_CONFIG_PATH);} else {- try {- userConfig = parseJSON(path.join(defaultDataDir, 'config.json'));- } catch (e) {- // do nothing- }+ userConfig = parseJSON(path.join(defaultDataDir, 'config.json'), true);}/** @type {Omit<import('./config-types.js').Config, 'mode' | 'serverFiles' | 'userFiles'>} */diff --git a/upcoming-release-notes/167.md b/upcoming-release-notes/167.mdnew file mode 100644index 0000000000..d72c984062--- /dev/null+++ b/upcoming-release-notes/167.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [Jackenmen]+---++Fix config.json in a default location getting silently ignored when it contains syntax errors.