diff --git a/src/main/java/com/blck/MusicReleaseTracker/JsonSettings/SettingsIO.java b/src/main/java/com/blck/MusicReleaseTracker/JsonSettings/SettingsIO.java index 10c832b..a0040ec 100644 --- a/src/main/java/com/blck/MusicReleaseTracker/JsonSettings/SettingsIO.java +++ b/src/main/java/com/blck/MusicReleaseTracker/JsonSettings/SettingsIO.java @@ -76,6 +76,8 @@ public void defaultSettings() { } public void migrateDataToReference(JsonNode reference, JsonNode current) { + if (current == null) + return; current.fieldNames().forEachRemaining(fieldName -> { if (reference.has(fieldName)) ((ObjectNode) reference).set(fieldName, current.get(fieldName)); @@ -97,7 +99,8 @@ public JsonNode readJsonFile(File file) { try { return objectMapper.readTree(file); } catch (IOException e) { - log.error(e, ErrorLogging.Severity.SEVERE, "settings file could not be read"); + log.error(e, ErrorLogging.Severity.WARNING, "error reading settings file - defaulting"); + defaultSettings(); } return null; } diff --git a/src/test/java/com/blck/MusicReleaseTracker/JsonSettings/SettingsIOTest.java b/src/test/java/com/blck/MusicReleaseTracker/JsonSettings/SettingsIOTest.java index 7ef6bda..4a95302 100644 --- a/src/test/java/com/blck/MusicReleaseTracker/JsonSettings/SettingsIOTest.java +++ b/src/test/java/com/blck/MusicReleaseTracker/JsonSettings/SettingsIOTest.java @@ -30,7 +30,7 @@ import java.nio.file.Path; import java.nio.file.Paths; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -63,6 +63,24 @@ void setUp() { lenient().when(valueStore.getConfigPath()).thenReturn(testSettingsPath); } + @Test + void readJsonFile() { + assertTrue(settingsIO.readJsonFile(settingsFile).size() > 1); + } + + + @Test + void readJsonFileParseExceptionTriggersReset() throws IOException { + try (FileWriter writer = new FileWriter(settingsFile)) { + writer.write("broken json ^%gb#%.#*-*"); + } + + var json = settingsIO.readJsonFile(settingsFile); + + assertNull(json); + verify(log, times(1)).error(any(), eq(ErrorLogging.Severity.WARNING), contains("error reading")); + } + @Test void readSetting() { assertEquals("false", settingsIO.readSetting("filterRemix")); diff --git a/vue/electron-main.js b/vue/electron-main.js index 324686b..ba40d50 100644 --- a/vue/electron-main.js +++ b/vue/electron-main.js @@ -60,6 +60,7 @@ async function checkBackendReady() { } app.whenReady().then(async () => { + // needs open backend in dev to run if (process.env.NODE_ENV !== "development") { externalEXE = spawn("buildResources/MusicReleaseTracker", { detached: true, stdio: "ignore" }); }