Expect more errors and rename

This commit is contained in:
crschnick 2024-02-29 09:49:23 +00:00
parent 9f55deb1e2
commit 3df16c22a4
10 changed files with 34 additions and 30 deletions

View file

@ -72,7 +72,7 @@ public class FileSystemHelper {
.evaluateExpression(shell.get(), path) .evaluateExpression(shell.get(), path)
.readStdoutOrThrow(); .readStdoutOrThrow();
} catch (Exception ex) { } catch (Exception ex) {
ErrorEvent.unreportable(ex); ErrorEvent.expected(ex);
throw ex; throw ex;
} }
} }
@ -123,14 +123,14 @@ public class FileSystemHelper {
} }
if (!model.getFileSystem().directoryExists(path)) { if (!model.getFileSystem().directoryExists(path)) {
throw ErrorEvent.unreportable( throw ErrorEvent.expected(
new IllegalArgumentException(String.format("Directory %s does not exist", path))); new IllegalArgumentException(String.format("Directory %s does not exist", path)));
} }
try { try {
model.getFileSystem().directoryAccessible(path); model.getFileSystem().directoryAccessible(path);
} catch (Exception ex) { } catch (Exception ex) {
ErrorEvent.unreportable(ex); ErrorEvent.expected(ex);
throw ex; throw ex;
} }
} }
@ -231,7 +231,7 @@ public class FileSystemHelper {
} }
if (source.getKind() == FileKind.DIRECTORY && target.getFileSystem().directoryExists(targetFile)) { if (source.getKind() == FileKind.DIRECTORY && target.getFileSystem().directoryExists(targetFile)) {
throw ErrorEvent.unreportable( throw ErrorEvent.expected(
new IllegalArgumentException("Target directory " + targetFile + " does already exist")); new IllegalArgumentException("Target directory " + targetFile + " does already exist"));
} }

View file

@ -315,7 +315,7 @@ public final class OpenFileSystemModel {
startIfNeeded(); startIfNeeded();
var abs = FileNames.join(getCurrentDirectory().getPath(), name); var abs = FileNames.join(getCurrentDirectory().getPath(), name);
if (fileSystem.directoryExists(abs)) { if (fileSystem.directoryExists(abs)) {
throw ErrorEvent.unreportable( throw ErrorEvent.expected(
new IllegalStateException(String.format("Directory %s already exists", abs))); new IllegalStateException(String.format("Directory %s already exists", abs)));
} }

View file

@ -276,7 +276,7 @@ public class StoreCreationComp extends DialogComp {
commit(); commit();
} catch (Throwable ex) { } catch (Throwable ex) {
if (ex instanceof ValidationException) { if (ex instanceof ValidationException) {
ErrorEvent.unreportable(ex); ErrorEvent.expected(ex);
skippable.set(false); skippable.set(false);
} else { } else {
skippable.set(true); skippable.set(true);

View file

@ -61,8 +61,8 @@ public class ErrorEvent {
return builder().description(msg); return builder().description(msg);
} }
public static <T extends Throwable> T unreportableIfEndsWith(T t, String... s) { public static <T extends Throwable> T expectedIfEndsWith(T t, String... s) {
return unreportableIf( return expectedIf(
t, t,
t.getMessage() != null t.getMessage() != null
&& Arrays.stream(s).map(String::toLowerCase).anyMatch(string -> t.getMessage() && Arrays.stream(s).map(String::toLowerCase).anyMatch(string -> t.getMessage()
@ -70,8 +70,8 @@ public class ErrorEvent {
.endsWith(string))); .endsWith(string)));
} }
public static <T extends Throwable> T unreportableIfContains(T t, String... s) { public static <T extends Throwable> T expectedIfContains(T t, String... s) {
return unreportableIf( return expectedIf(
t, t,
t.getMessage() != null t.getMessage() != null
&& Arrays.stream(s).map(String::toLowerCase).anyMatch(string -> t.getMessage() && Arrays.stream(s).map(String::toLowerCase).anyMatch(string -> t.getMessage()
@ -79,14 +79,14 @@ public class ErrorEvent {
.contains(string))); .contains(string)));
} }
public static <T extends Throwable> T unreportableIf(T t, boolean b) { public static <T extends Throwable> T expectedIf(T t, boolean b) {
if (b) { if (b) {
EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).expected()); EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).expected());
} }
return t; return t;
} }
public static <T extends Throwable> T unreportable(T t) { public static <T extends Throwable> T expected(T t) {
EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).expected()); EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).expected());
return t; return t;
} }

View file

@ -115,7 +115,7 @@ public abstract class ExternalApplicationType implements PrefsChoiceValue {
protected void launch(String title, String args) throws Exception { protected void launch(String title, String args) throws Exception {
try (ShellControl pc = LocalShell.getShell()) { try (ShellControl pc = LocalShell.getShell()) {
if (!ApplicationHelper.isInPath(pc, executable)) { if (!ApplicationHelper.isInPath(pc, executable)) {
throw ErrorEvent.unreportable( throw ErrorEvent.expected(
new IOException( new IOException(
"Executable " + executable "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.")); + " 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."));

View file

@ -101,7 +101,7 @@ public interface ExternalEditorType extends PrefsChoiceValue {
public void launch(Path file) throws Exception { public void launch(Path file) throws Exception {
var customCommand = AppPrefs.get().customEditorCommand().getValue(); var customCommand = AppPrefs.get().customEditorCommand().getValue();
if (customCommand == null || customCommand.isBlank()) { 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 = var format =
@ -257,7 +257,7 @@ public interface ExternalEditorType extends PrefsChoiceValue {
if (location.isEmpty()) { if (location.isEmpty()) {
location = determineInstallation(); location = determineInstallation();
if (location.isEmpty()) { if (location.isEmpty()) {
throw ErrorEvent.unreportable( throw ErrorEvent.expected(
new IOException("Unable to find installation of " + toTranslatedString())); new IOException("Unable to find installation of " + toTranslatedString()));
} }
} }

View file

@ -830,7 +830,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
public void launch(LaunchConfiguration configuration) throws Exception { public void launch(LaunchConfiguration configuration) throws Exception {
var custom = AppPrefs.get().customTerminalCommand().getValue(); var custom = AppPrefs.get().customTerminalCommand().getValue();
if (custom == null || custom.isBlank()) { 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"; var format = custom.toLowerCase(Locale.ROOT).contains("$cmd") ? custom : custom + " $CMD";

View file

@ -122,6 +122,7 @@ public class AppDownloads {
} }
public static Optional<GHRelease> getLatestSuitableRelease() throws IOException { public static Optional<GHRelease> getLatestSuitableRelease() throws IOException {
try {
var preIncluding = getTopReleaseIncludingPreRelease(); var preIncluding = getTopReleaseIncludingPreRelease();
// If we are currently running a prerelease, always return this as the suitable release! // If we are currently running a prerelease, always return this as the suitable release!
if (preIncluding.isPresent() if (preIncluding.isPresent()
@ -131,6 +132,9 @@ public class AppDownloads {
} }
return getMarkedLatestRelease(); return getMarkedLatestRelease();
} catch (IOException e) {
throw ErrorEvent.expected(e);
}
} }
public static Optional<GHRelease> getRelease(String version, boolean omitErrors) { public static Optional<GHRelease> getRelease(String version, boolean omitErrors) {
@ -138,7 +142,7 @@ public class AppDownloads {
var repo = getRepository(); var repo = getRepository();
return Optional.ofNullable(repo.getReleaseByTagName(version)); return Optional.ofNullable(repo.getReleaseByTagName(version));
} catch (IOException e) { } catch (IOException e) {
ErrorEvent.fromThrowable(e).omitted(omitErrors).handle(); ErrorEvent.fromThrowable(e).omitted(omitErrors).expected().handle();
return Optional.empty(); return Optional.empty();
} }
} }

View file

@ -70,7 +70,7 @@ public class ApplicationHelper {
ShellControl processControl, String executable, String displayName, DataStoreEntry connection) ShellControl processControl, String executable, String displayName, DataStoreEntry connection)
throws Exception { throws Exception {
if (!isInPath(processControl, executable)) { 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() : ""))); + " not found in PATH" + (connection != null ? " on system " + connection.getName() : "")));
} }
} }
@ -78,7 +78,7 @@ public class ApplicationHelper {
public static void isSupported(FailableSupplier<Boolean> supplier, String displayName, DataStoreEntry connection) public static void isSupported(FailableSupplier<Boolean> supplier, String displayName, DataStoreEntry connection)
throws Exception { throws Exception {
if (!supplier.get()) { 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() : ""))); + (connection != null ? " on system " + connection.getName() : "")));
} }
} }

View file

@ -18,7 +18,7 @@ public class TerminalLauncher {
public static void openDirect(String title, ShellControl shellControl, String command) throws Exception { public static void openDirect(String title, ShellControl shellControl, String command) throws Exception {
var type = AppPrefs.get().terminalType().getValue(); var type = AppPrefs.get().terminalType().getValue();
if (type == null) { 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 script = ScriptHelper.createLocalExecScript(command);
var config = new ExternalTerminalType.LaunchConfiguration( 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 { public static void open(DataStoreEntry entry, String title, String directory, ProcessControl cc) throws Exception {
var type = AppPrefs.get().terminalType().getValue(); var type = AppPrefs.get().terminalType().getValue();
if (type == null) { 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; var color = entry != null ? DataStorage.get().getRootForEntry(entry).getColor() : null;
@ -56,7 +56,7 @@ public class TerminalLauncher {
type.launch(config); type.launch(config);
latch.await(); latch.await();
} catch (Exception ex) { } catch (Exception ex) {
ErrorEvent.unreportable(new IOException( ErrorEvent.expected(new IOException(
"Unable to launch terminal " + type.toTranslatedString().getValue() + ": " + ex.getMessage() "Unable to launch terminal " + type.toTranslatedString().getValue() + ": " + ex.getMessage()
+ ".\nMaybe try to use a different terminal in the settings.", + ".\nMaybe try to use a different terminal in the settings.",
ex)); ex));