From 52102bff3167713b5b6b895089063b799145cee5 Mon Sep 17 00:00:00 2001 From: crschnick Date: Sat, 3 Aug 2024 01:50:04 +0000 Subject: [PATCH] Improve shell error messages --- .../main/java/io/xpipe/core/process/ShellDumbMode.java | 10 ++++++++++ .../java/io/xpipe/core/store/ConnectionFileSystem.java | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/io/xpipe/core/process/ShellDumbMode.java b/core/src/main/java/io/xpipe/core/process/ShellDumbMode.java index 20573ed72..3faa460c2 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellDumbMode.java +++ b/core/src/main/java/io/xpipe/core/process/ShellDumbMode.java @@ -8,6 +8,8 @@ public interface ShellDumbMode { return true; } + default void throwIfUnsupported() {} + default ShellDialect getSwitchDialect() { return null; } @@ -25,6 +27,14 @@ public interface ShellDumbMode { class Unsupported implements ShellDumbMode { + private final String message; + + public Unsupported(String message) {this.message = message;} + + public void throwIfUnsupported() { + throw new UnsupportedOperationException(message); + } + @Override public boolean supportsAnyPossibleInteraction() { return false; diff --git a/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java b/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java index 22f0f42a3..c5331bbc9 100644 --- a/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java +++ b/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java @@ -1,9 +1,8 @@ package io.xpipe.core.store; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.xpipe.core.process.CommandBuilder; import io.xpipe.core.process.ShellControl; - -import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import java.io.InputStream; @@ -37,9 +36,10 @@ public class ConnectionFileSystem implements FileSystem { @Override public FileSystem open() throws Exception { shellControl.start(); - if (!shellControl.getShellDialect().getDumbMode().supportsAnyPossibleInteraction()) { + var d = shellControl.getShellDialect().getDumbMode(); + if (!d.supportsAnyPossibleInteraction()) { shellControl.close(); - throw new UnsupportedOperationException("System shell does not support file system interaction"); + d.throwIfUnsupported(); } return this; }