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)
.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"));
}

View file

@ -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)));
}

View file

@ -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);

View file

@ -61,8 +61,8 @@ public class ErrorEvent {
return builder().description(msg);
}
public static <T extends Throwable> T unreportableIfEndsWith(T t, String... s) {
return unreportableIf(
public static <T extends Throwable> 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 extends Throwable> T unreportableIfContains(T t, String... s) {
return unreportableIf(
public static <T extends Throwable> 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 extends Throwable> T unreportableIf(T t, boolean b) {
public static <T extends Throwable> T expectedIf(T t, boolean b) {
if (b) {
EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).expected());
}
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());
return t;
}

View file

@ -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."));

View file

@ -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()));
}
}

View file

@ -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";

View file

@ -122,15 +122,19 @@ public class AppDownloads {
}
public static Optional<GHRelease> 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<GHRelease> 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();
}
}

View file

@ -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<Boolean> 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() : "")));
}
}

View file

@ -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));