Skip to content

Commit

Permalink
fix json parsing #98 (#103)
Browse files Browse the repository at this point in the history
* fix - polling

* lifecycle

* fix json parsing error
  • Loading branch information
BLCK-B authored Oct 25, 2024
1 parent 0aec9f7 commit fc61b2c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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"));
Expand Down
1 change: 1 addition & 0 deletions vue/electron-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
}
Expand Down

0 comments on commit fc61b2c

Please sign in to comment.