Starting the rudimentary log tracking. At this time, just exceptions.

This commit is contained in:
a2geek committed 2026-10-21 17:48:11 -05:00
1 parent f108753d2a
commit cd794232a7
3 files changed
+50 -2

No files matched your search

@@ -290,7 +290,32 @@ public class FileStoreWindow {
Settings.setLastOpenedDirectory(selectedFile.getParentFile());
Optional<Source> source = Sources.create(selectedFile);
var inspected = FileStores.inspect(source.orElseThrow());
openFileStore(inspected.fileStores, true);
if (!inspected.fileStores.isEmpty()) {
openFileStore(inspected.fileStores, true);
}
else if (!inspected.messages.isEmpty()) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Unable to open image");
alert.setHeaderText("Image format not recognized.");
StringBuilder content = new StringBuilder();
content.append("Errors occurred while opening image:\n");
inspected.messages.forEach(message -> {
content.append("* ").append(message.message()).append("\n");
});
alert.setContentText(content.toString());
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
alert.showAndWait();
}
else {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Unable to open image");
alert.setHeaderText("Image format not recognized.");
alert.setContentText("The image format was not recognized. No error occurred.");
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
alert.showAndWait();
}
}
public void openFileStore(List<FileStore> fileStores, boolean promptForWindow) {
@@ -63,6 +63,7 @@ public interface FileStoreFactory {
public final Source source;
public final NibbleTrackReaderWriter nibbleTrackReaderWriter;
public final List<FileStore> fileStores = new ArrayList<>();
public final List<Message> messages = new ArrayList<>();
public Context(Source source) {
this.source = source;
@@ -215,4 +216,22 @@ public interface FileStoreFactory {
}
}
}
record Message(Level level, String message) {
public static Message info(String fmt, Object... args) {
return new Message(Level.INFO, String.format(fmt, args));
}
public static Message warning(String fmt, Object... args) {
return new Message(Level.WARNING, String.format(fmt, args));
}
public static Message error(String fmt, Object... args) {
return new Message(Level.ERROR, String.format(fmt, args));
}
}
enum Level {
INFO,
WARNING,
ERROR
}
}
@@ -57,7 +57,11 @@ public class FileStores {
try {
factory.inspect(ctx);
} catch (Throwable t) {
// ignore it
// Find the root cause
while (t.getCause() != null) {
t = t.getCause();
}
ctx.messages.add(FileStoreFactory.Message.error(t.getMessage()));
}
});
return ctx;