Skip to content

Commit

Permalink
Fix process not starting if output directory didn't exist
Browse files Browse the repository at this point in the history
The error was silently swallowed by the JavaFX thread handler.
It is not properly captured, but more importantly before saving
the config file we make sure the output directory is created.
  • Loading branch information
melix committed May 15, 2023
1 parent 26681d0 commit 67d2b16
Show file tree
Hide file tree
Showing 2 changed files with 207 additions and 184 deletions.
Expand Up @@ -17,6 +17,8 @@

import com.google.gson.Gson;
import me.champeau.a4j.ser.ColorMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -33,6 +35,8 @@
import java.time.ZonedDateTime;

abstract class ProcessParamsIO {
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessParamsIO.class);

private ProcessParamsIO() {

}
Expand Down Expand Up @@ -61,6 +65,7 @@ public static ProcessParams loadDefaults() {
if (params != null) {
return params;
}
LOGGER.info("No config file found at {}. Using default parameters", defaultsFile);
return new ProcessParams(
new SpectrumParams(SpectralRay.H_ALPHA, SpectralRay.H_ALPHA.getDetectionThreshold(), 0, 3),
new ObservationDetails(
Expand Down Expand Up @@ -134,9 +139,12 @@ public static ProcessParams readFrom(Path configFile) {
}

public static void saveTo(ProcessParams params, File destination) {
try (var writer = new OutputStreamWriter(new FileOutputStream(destination), StandardCharsets.UTF_8)) {
var gson = newGson();
writer.write(gson.toJson(params));
try {
Files.createDirectories(destination.getParentFile().toPath());
try (var writer = new OutputStreamWriter(new FileOutputStream(destination), StandardCharsets.UTF_8)) {
var gson = newGson();
writer.write(gson.toJson(params));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 67d2b16

Please sign in to comment.