mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-06-21 14:00:57 -04:00
Make error handlers consistent
This commit is contained in:
@@ -10,8 +10,6 @@ import java.awt.*;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import static io.xpipe.app.core.mode.OperationMode.BACKGROUND;
|
||||
|
||||
public class AppTray {
|
||||
|
||||
private static AppTray INSTANCE;
|
||||
@@ -28,7 +26,7 @@ public class AppTray {
|
||||
if (AppProperties.get().isDeveloperMode()) {
|
||||
builder.menuItem("Throw exception", e -> {
|
||||
Platform.runLater(() -> {
|
||||
throw new RuntimeException("This is a text exception");
|
||||
throw new RuntimeException("This is a test exception");
|
||||
});
|
||||
})
|
||||
.menuItem("Throw terminal exception", e -> {
|
||||
@@ -85,8 +83,6 @@ public class AppTray {
|
||||
|
||||
@Override
|
||||
public void handle(ErrorEvent event) {
|
||||
BACKGROUND.getErrorHandler().handle(event);
|
||||
|
||||
if (event.isOmitted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,7 @@ package io.xpipe.app.core.mode;
|
||||
import io.xpipe.app.comp.storage.collection.SourceCollectionViewState;
|
||||
import io.xpipe.app.comp.storage.store.StoreViewState;
|
||||
import io.xpipe.app.core.*;
|
||||
import io.xpipe.app.issue.BasicErrorHandler;
|
||||
import io.xpipe.app.issue.ErrorHandler;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.app.issue.*;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.app.update.AppUpdater;
|
||||
@@ -59,6 +57,10 @@ public class BaseMode extends OperationMode {
|
||||
|
||||
@Override
|
||||
public ErrorHandler getErrorHandler() {
|
||||
return new BasicErrorHandler();
|
||||
var log = new LogErrorHandler();
|
||||
return event -> {
|
||||
log.handle(event);
|
||||
ErrorAction.ignore().handle(event);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,7 @@ package io.xpipe.app.core.mode;
|
||||
|
||||
import io.xpipe.app.core.App;
|
||||
import io.xpipe.app.core.AppGreetings;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.issue.ErrorHandler;
|
||||
import io.xpipe.app.issue.ErrorHandlerComp;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.app.issue.*;
|
||||
import io.xpipe.app.update.UpdateChangelogAlert;
|
||||
import javafx.application.Platform;
|
||||
|
||||
@@ -56,11 +53,10 @@ public class GuiMode extends PlatformMode {
|
||||
|
||||
@Override
|
||||
public ErrorHandler getErrorHandler() {
|
||||
var log = new LogErrorHandler();
|
||||
return event -> {
|
||||
BACKGROUND.getErrorHandler().handle(event);
|
||||
if (App.isPlatformRunning() && !event.isOmitted()) {
|
||||
ErrorHandlerComp.showAndWait(event);
|
||||
}
|
||||
log.handle(event);
|
||||
ErrorHandlerComp.showAndWait(event);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ package io.xpipe.app.core.mode;
|
||||
import com.dustinredmond.fxtrayicon.FXTrayIcon;
|
||||
import io.xpipe.app.core.App;
|
||||
import io.xpipe.app.core.AppTray;
|
||||
import io.xpipe.app.issue.ErrorHandler;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.app.issue.*;
|
||||
|
||||
public class TrayMode extends PlatformMode {
|
||||
|
||||
@@ -45,10 +44,14 @@ public class TrayMode extends PlatformMode {
|
||||
|
||||
@Override
|
||||
public ErrorHandler getErrorHandler() {
|
||||
if (AppTray.get() != null) {
|
||||
return AppTray.get().getErrorHandler();
|
||||
} else {
|
||||
return BACKGROUND.getErrorHandler();
|
||||
}
|
||||
var log = new LogErrorHandler();
|
||||
return event -> {
|
||||
// Check if tray initialization is finished
|
||||
if (AppTray.get() != null) {
|
||||
AppTray.get().getErrorHandler().handle(event);
|
||||
}
|
||||
log.handle(event);
|
||||
ErrorAction.ignore().handle(event);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,10 @@ public class ErrorDetailsComp extends SimpleComp {
|
||||
AppI18n.observable("stackTrace"), "mdoal-code", Comp.of(this::createStrackTraceContent)));
|
||||
}
|
||||
|
||||
if (event.getTrackEvents().size() > 0) {
|
||||
items.add(new TabPaneComp.Entry(
|
||||
AppI18n.observable("events"), "mdi2c-clipboard-list-outline", createTrackEventHistory()));
|
||||
}
|
||||
// if (event.getTrackEvents().size() > 0) {
|
||||
// items.add(new TabPaneComp.Entry(
|
||||
// AppI18n.observable("events"), "mdi2c-clipboard-list-outline", createTrackEventHistory()));
|
||||
// }
|
||||
|
||||
var tb = new TabPaneComp(new SimpleObjectProperty<>(items.get(0)), items);
|
||||
tb.apply(r -> AppFont.small(r.get()));
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.xpipe.app.issue;
|
||||
|
||||
import io.xpipe.app.comp.base.ButtonComp;
|
||||
import io.xpipe.app.comp.base.TitledPaneComp;
|
||||
import io.xpipe.app.core.App;
|
||||
import io.xpipe.app.core.AppFont;
|
||||
import io.xpipe.app.core.AppI18n;
|
||||
import io.xpipe.app.core.AppWindowHelper;
|
||||
@@ -43,6 +44,11 @@ public class ErrorHandlerComp extends SimpleComp {
|
||||
}
|
||||
|
||||
public static void showAndWait(ErrorEvent event) {
|
||||
if (!App.isPlatformRunning() || event.isOmitted()) {
|
||||
ErrorAction.ignore().handle(event);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Platform.isFxApplicationThread()) {
|
||||
showAndWaitWithPlatformThread(event);
|
||||
} else {
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.xpipe.app.issue;
|
||||
import io.xpipe.app.core.AppLogs;
|
||||
import io.xpipe.core.util.Deobfuscator;
|
||||
|
||||
public class BasicErrorHandler implements ErrorHandler {
|
||||
public class LogErrorHandler implements ErrorHandler {
|
||||
|
||||
@Override
|
||||
public void handle(ErrorEvent event) {
|
||||
@@ -14,7 +14,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class TerminalErrorHandler implements ErrorHandler {
|
||||
|
||||
private final ErrorHandler basic = new BasicErrorHandler();
|
||||
private final ErrorHandler basic = new LogErrorHandler();
|
||||
|
||||
@Override
|
||||
public void handle(ErrorEvent event) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package io.xpipe.app.launcher;
|
||||
import io.xpipe.app.core.AppLock;
|
||||
import io.xpipe.app.core.AppLogs;
|
||||
import io.xpipe.app.core.mode.OperationMode;
|
||||
import io.xpipe.app.issue.BasicErrorHandler;
|
||||
import io.xpipe.app.issue.LogErrorHandler;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.app.util.ThreadHelper;
|
||||
@@ -41,14 +41,14 @@ public class LauncherCommand implements Callable<Integer> {
|
||||
|
||||
var cmd = new CommandLine(new LauncherCommand());
|
||||
cmd.setExecutionExceptionHandler((ex, commandLine, parseResult) -> {
|
||||
new BasicErrorHandler()
|
||||
new LogErrorHandler()
|
||||
.handle(ErrorEvent.fromThrowable("Launcher command error occurred", ex)
|
||||
.build());
|
||||
OperationMode.halt(1);
|
||||
return 1;
|
||||
});
|
||||
cmd.setParameterExceptionHandler((ex, args1) -> {
|
||||
new BasicErrorHandler()
|
||||
new LogErrorHandler()
|
||||
.handle(ErrorEvent.fromThrowable("Launcher parameter error occurred", ex)
|
||||
.build());
|
||||
OperationMode.halt(1);
|
||||
|
||||
Reference in New Issue
Block a user