fix(json-config-loading): Fix handling invalid AutoConfigs and config writing
@@ -84,7 +84,7 @@ public void loadConfigsIn(Context context) {
try (InputStream inputStream = Files.newInputStream(configPath, StandardOpenOption.READ)) {
T loadedConfig = (T) serializer.deserialize(TypeInfo.of(configClass), inputStream).get();
mergeConfig(configClass, loadedConfig, config);
- } catch (IOException e) {
+ } catch (Exception e) {
logger.error("Error while loading config {} from disk", config.getId(), e);
}
}
@@ -112,7 +112,8 @@ public void saveConfigsToDisk() {
private void saveConfigToDisk(AutoConfig config) {
// TODO: Save when screen for config closed
Path configPath = getConfigPath(config.getId());
- try (OutputStream output = Files.newOutputStream(configPath, StandardOpenOption.CREATE)) {
+ try (OutputStream output = Files.newOutputStream(configPath, StandardOpenOption.TRUNCATE_EXISTING,
+ StandardOpenOption.CREATE)) {
serializer.serialize(config, TypeInfo.of((Class<AutoConfig>) config.getClass()), output);
} catch (IOException e) {
logger.error("Error while saving config {} to disk", config.getId(), e);
