From 3df16c22a46f03de804d4584ec566346e1f64f06 Mon Sep 17 00:00:00 2001 From: crschnick Date: Thu, 29 Feb 2024 09:49:23 +0000 Subject: [PATCH] Expect more errors and rename --- .../xpipe/app/browser/FileSystemHelper.java | 8 +++---- .../app/browser/OpenFileSystemModel.java | 2 +- .../app/comp/store/StoreCreationComp.java | 2 +- .../java/io/xpipe/app/issue/ErrorEvent.java | 12 +++++----- .../app/prefs/ExternalApplicationType.java | 2 +- .../xpipe/app/prefs/ExternalEditorType.java | 4 ++-- .../xpipe/app/prefs/ExternalTerminalType.java | 2 +- .../io/xpipe/app/update/AppDownloads.java | 22 +++++++++++-------- .../io/xpipe/app/util/ApplicationHelper.java | 4 ++-- .../io/xpipe/app/util/TerminalLauncher.java | 6 ++--- 10 files changed, 34 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java index b7d618317..ebbe2d8bd 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java +++ b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java @@ -72,7 +72,7 @@ public class FileSystemHelper { .evaluateExpression(shell.get(), path) .readStdoutOrThrow(); } catch (Exception ex) { - ErrorEvent.unreportable(ex); + ErrorEvent.expected(ex); throw ex; } } @@ -123,14 +123,14 @@ public class FileSystemHelper { } if (!model.getFileSystem().directoryExists(path)) { - throw ErrorEvent.unreportable( + throw ErrorEvent.expected( new IllegalArgumentException(String.format("Directory %s does not exist", path))); } try { model.getFileSystem().directoryAccessible(path); } catch (Exception ex) { - ErrorEvent.unreportable(ex); + ErrorEvent.expected(ex); throw ex; } } @@ -231,7 +231,7 @@ public class FileSystemHelper { } if (source.getKind() == FileKind.DIRECTORY && target.getFileSystem().directoryExists(targetFile)) { - throw ErrorEvent.unreportable( + throw ErrorEvent.expected( new IllegalArgumentException("Target directory " + targetFile + " does already exist")); } diff --git a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java index e23886035..33e1633fc 100644 --- a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java @@ -315,7 +315,7 @@ public final class OpenFileSystemModel { startIfNeeded(); var abs = FileNames.join(getCurrentDirectory().getPath(), name); if (fileSystem.directoryExists(abs)) { - throw ErrorEvent.unreportable( + throw ErrorEvent.expected( new IllegalStateException(String.format("Directory %s already exists", abs))); } diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreCreationComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreCreationComp.java index 59c2d5fda..4a448051c 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreCreationComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreCreationComp.java @@ -276,7 +276,7 @@ public class StoreCreationComp extends DialogComp { commit(); } catch (Throwable ex) { if (ex instanceof ValidationException) { - ErrorEvent.unreportable(ex); + ErrorEvent.expected(ex); skippable.set(false); } else { skippable.set(true); diff --git a/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java b/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java index e921d4be5..7dc847a27 100644 --- a/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java +++ b/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java @@ -61,8 +61,8 @@ public class ErrorEvent { return builder().description(msg); } - public static T unreportableIfEndsWith(T t, String... s) { - return unreportableIf( + public static T expectedIfEndsWith(T t, String... s) { + return expectedIf( t, t.getMessage() != null && Arrays.stream(s).map(String::toLowerCase).anyMatch(string -> t.getMessage() @@ -70,8 +70,8 @@ public class ErrorEvent { .endsWith(string))); } - public static T unreportableIfContains(T t, String... s) { - return unreportableIf( + public static T expectedIfContains(T t, String... s) { + return expectedIf( t, t.getMessage() != null && Arrays.stream(s).map(String::toLowerCase).anyMatch(string -> t.getMessage() @@ -79,14 +79,14 @@ public class ErrorEvent { .contains(string))); } - public static T unreportableIf(T t, boolean b) { + public static T expectedIf(T t, boolean b) { if (b) { EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).expected()); } return t; } - public static T unreportable(T t) { + public static T expected(T t) { EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).expected()); return t; } diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalApplicationType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalApplicationType.java index 984220647..a6f6e2a5c 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalApplicationType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalApplicationType.java @@ -115,7 +115,7 @@ public abstract class ExternalApplicationType implements PrefsChoiceValue { protected void launch(String title, String args) throws Exception { try (ShellControl pc = LocalShell.getShell()) { if (!ApplicationHelper.isInPath(pc, executable)) { - throw ErrorEvent.unreportable( + throw ErrorEvent.expected( new IOException( "Executable " + executable + " not found in PATH. Either add it to the PATH and refresh the environment by restarting XPipe, or specify an absolute executable path using the custom terminal setting.")); diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java index 6b154c9d9..c9e83f619 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalEditorType.java @@ -101,7 +101,7 @@ public interface ExternalEditorType extends PrefsChoiceValue { public void launch(Path file) throws Exception { var customCommand = AppPrefs.get().customEditorCommand().getValue(); if (customCommand == null || customCommand.isBlank()) { - throw ErrorEvent.unreportable(new IllegalStateException("No custom editor command specified")); + throw ErrorEvent.expected(new IllegalStateException("No custom editor command specified")); } var format = @@ -257,7 +257,7 @@ public interface ExternalEditorType extends PrefsChoiceValue { if (location.isEmpty()) { location = determineInstallation(); if (location.isEmpty()) { - throw ErrorEvent.unreportable( + throw ErrorEvent.expected( new IOException("Unable to find installation of " + toTranslatedString())); } } diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java index c9712a9e4..af71e7c8a 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java @@ -830,7 +830,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { public void launch(LaunchConfiguration configuration) throws Exception { var custom = AppPrefs.get().customTerminalCommand().getValue(); if (custom == null || custom.isBlank()) { - throw ErrorEvent.unreportable(new IllegalStateException("No custom terminal command specified")); + throw ErrorEvent.expected(new IllegalStateException("No custom terminal command specified")); } var format = custom.toLowerCase(Locale.ROOT).contains("$cmd") ? custom : custom + " $CMD"; diff --git a/app/src/main/java/io/xpipe/app/update/AppDownloads.java b/app/src/main/java/io/xpipe/app/update/AppDownloads.java index 9bfb3dbe1..b34ca98e5 100644 --- a/app/src/main/java/io/xpipe/app/update/AppDownloads.java +++ b/app/src/main/java/io/xpipe/app/update/AppDownloads.java @@ -122,15 +122,19 @@ public class AppDownloads { } public static Optional getLatestSuitableRelease() throws IOException { - var preIncluding = getTopReleaseIncludingPreRelease(); - // If we are currently running a prerelease, always return this as the suitable release! - if (preIncluding.isPresent() - && preIncluding.get().isPrerelease() - && AppProperties.get().getVersion().equals(preIncluding.get().getTagName())) { - return preIncluding; - } + try { + var preIncluding = getTopReleaseIncludingPreRelease(); + // If we are currently running a prerelease, always return this as the suitable release! + if (preIncluding.isPresent() + && preIncluding.get().isPrerelease() + && AppProperties.get().getVersion().equals(preIncluding.get().getTagName())) { + return preIncluding; + } - return getMarkedLatestRelease(); + return getMarkedLatestRelease(); + } catch (IOException e) { + throw ErrorEvent.expected(e); + } } public static Optional getRelease(String version, boolean omitErrors) { @@ -138,7 +142,7 @@ public class AppDownloads { var repo = getRepository(); return Optional.ofNullable(repo.getReleaseByTagName(version)); } catch (IOException e) { - ErrorEvent.fromThrowable(e).omitted(omitErrors).handle(); + ErrorEvent.fromThrowable(e).omitted(omitErrors).expected().handle(); return Optional.empty(); } } diff --git a/app/src/main/java/io/xpipe/app/util/ApplicationHelper.java b/app/src/main/java/io/xpipe/app/util/ApplicationHelper.java index f787d43f2..aeaa1873e 100644 --- a/app/src/main/java/io/xpipe/app/util/ApplicationHelper.java +++ b/app/src/main/java/io/xpipe/app/util/ApplicationHelper.java @@ -70,7 +70,7 @@ public class ApplicationHelper { ShellControl processControl, String executable, String displayName, DataStoreEntry connection) throws Exception { if (!isInPath(processControl, executable)) { - throw ErrorEvent.unreportable(new IOException(displayName + " executable " + executable + throw ErrorEvent.expected(new IOException(displayName + " executable " + executable + " not found in PATH" + (connection != null ? " on system " + connection.getName() : ""))); } } @@ -78,7 +78,7 @@ public class ApplicationHelper { public static void isSupported(FailableSupplier supplier, String displayName, DataStoreEntry connection) throws Exception { if (!supplier.get()) { - throw ErrorEvent.unreportable(new IOException(displayName + " is not supported" + throw ErrorEvent.expected(new IOException(displayName + " is not supported" + (connection != null ? " on system " + connection.getName() : ""))); } } diff --git a/app/src/main/java/io/xpipe/app/util/TerminalLauncher.java b/app/src/main/java/io/xpipe/app/util/TerminalLauncher.java index 6550853ed..d4dae7231 100644 --- a/app/src/main/java/io/xpipe/app/util/TerminalLauncher.java +++ b/app/src/main/java/io/xpipe/app/util/TerminalLauncher.java @@ -18,7 +18,7 @@ public class TerminalLauncher { public static void openDirect(String title, ShellControl shellControl, String command) throws Exception { var type = AppPrefs.get().terminalType().getValue(); if (type == null) { - throw ErrorEvent.unreportable(new IllegalStateException(AppI18n.get("noTerminalSet"))); + throw ErrorEvent.expected(new IllegalStateException(AppI18n.get("noTerminalSet"))); } var script = ScriptHelper.createLocalExecScript(command); var config = new ExternalTerminalType.LaunchConfiguration( @@ -33,7 +33,7 @@ public class TerminalLauncher { public static void open(DataStoreEntry entry, String title, String directory, ProcessControl cc) throws Exception { var type = AppPrefs.get().terminalType().getValue(); if (type == null) { - throw ErrorEvent.unreportable(new IllegalStateException(AppI18n.get("noTerminalSet"))); + throw ErrorEvent.expected(new IllegalStateException(AppI18n.get("noTerminalSet"))); } var color = entry != null ? DataStorage.get().getRootForEntry(entry).getColor() : null; @@ -56,7 +56,7 @@ public class TerminalLauncher { type.launch(config); latch.await(); } catch (Exception ex) { - ErrorEvent.unreportable(new IOException( + ErrorEvent.expected(new IOException( "Unable to launch terminal " + type.toTranslatedString().getValue() + ": " + ex.getMessage() + ".\nMaybe try to use a different terminal in the settings.", ex));