mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 09:00:26 +00:00
Shell error handling fixes
This commit is contained in:
parent
73efb183e7
commit
9abd19483f
10 changed files with 32 additions and 15 deletions
|
@ -31,7 +31,7 @@ public interface BrowserAction {
|
|||
.orElseThrow();
|
||||
}
|
||||
|
||||
default void init(OpenFileSystemModel model) {}
|
||||
default void init(OpenFileSystemModel model) throws Exception {}
|
||||
|
||||
default String getProFeatureId() {
|
||||
return null;
|
||||
|
|
|
@ -239,7 +239,8 @@ public class AppSocketServer {
|
|||
}
|
||||
} catch (SocketException ex) {
|
||||
// Omit it, as this might happen often
|
||||
ErrorEvent.fromThrowable(ex).omitted(true).build().handle();
|
||||
// This is expected if you kill a running xpipe CLI process
|
||||
ErrorEvent.fromThrowable(ex).expected().omit().build().handle();
|
||||
} catch (Throwable ex) {
|
||||
ErrorEvent.fromThrowable(ex).build().handle();
|
||||
} finally {
|
||||
|
|
|
@ -26,7 +26,7 @@ public interface ActionProvider {
|
|||
}
|
||||
}
|
||||
|
||||
default void init() {}
|
||||
default void init() throws Exception {}
|
||||
|
||||
default String getId() {
|
||||
return null;
|
||||
|
|
|
@ -39,8 +39,7 @@ public class EventHandlerImpl extends EventHandler {
|
|||
|
||||
// Don't block shutdown
|
||||
if (OperationMode.isInShutdown()) {
|
||||
SentryErrorHandler.getInstance().handle(ee);
|
||||
handle(fromErrorEvent(ee));
|
||||
handleOnShutdown(ee);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -51,6 +50,11 @@ public class EventHandlerImpl extends EventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private void handleOnShutdown(ErrorEvent ee) {
|
||||
ErrorAction.ignore().handle(ee);
|
||||
handle(fromErrorEvent(ee));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modify(ErrorEvent ee) {
|
||||
if (AppLogs.get() != null && AppLogs.get().getSessionLogsDirectory() != null) {
|
||||
|
|
|
@ -36,6 +36,7 @@ public class GuiErrorHandler extends GuiErrorHandlerBase implements ErrorHandler
|
|||
if (lex.isPresent()) {
|
||||
LicenseProvider.get().showLicenseAlert(lex.get());
|
||||
event.setShouldSendDiagnostics(true);
|
||||
event.clearAttachments();
|
||||
ErrorAction.ignore().handle(event);
|
||||
} else {
|
||||
ErrorHandlerComp.showAndTryWait(event, true);
|
||||
|
|
|
@ -141,7 +141,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected CommandBuilder toCommand(LaunchConfiguration configuration) {
|
||||
protected CommandBuilder toCommand(LaunchConfiguration configuration) throws Exception {
|
||||
// A weird behavior in Windows Terminal causes the trailing
|
||||
// backslash of a filepath to escape the closing quote in the title argument
|
||||
// So just remove that slash
|
||||
|
@ -894,6 +894,6 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
|||
launch(configuration.getColoredTitle(), args);
|
||||
}
|
||||
|
||||
protected abstract CommandBuilder toCommand(LaunchConfiguration configuration);
|
||||
protected abstract CommandBuilder toCommand(LaunchConfiguration configuration) throws Exception;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,9 @@ public class LocalShell {
|
|||
}
|
||||
|
||||
public static ShellControl getLocalPowershell() throws Exception {
|
||||
if (ShellDialects.isPowershell(getShell())) {
|
||||
return local;
|
||||
var s = getShell();
|
||||
if (ShellDialects.isPowershell(s)) {
|
||||
return s;
|
||||
}
|
||||
|
||||
if (localPowershell == null) {
|
||||
|
@ -29,18 +30,18 @@ public class LocalShell {
|
|||
.subShell(ShellDialects.POWERSHELL)
|
||||
.start();
|
||||
}
|
||||
return localPowershell;
|
||||
return localPowershell.start();
|
||||
}
|
||||
|
||||
public static boolean isLocalShellInitialized() {
|
||||
return local != null;
|
||||
}
|
||||
|
||||
public static ShellControl getShell() {
|
||||
public static ShellControl getShell() throws Exception {
|
||||
if (local == null) {
|
||||
throw new IllegalStateException("Local shell not initialized yet");
|
||||
}
|
||||
|
||||
return local;
|
||||
return local.start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,7 +133,9 @@ public class ScanAlert {
|
|||
}
|
||||
});
|
||||
} finally {
|
||||
shellControl.close();
|
||||
if (shellControl != null) {
|
||||
shellControl.close();
|
||||
}
|
||||
shellControl = null;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.xpipe.app.util;
|
||||
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.util.FailableSupplier;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -36,6 +37,12 @@ public class ShellControlCache {
|
|||
multiPurposeCache.computeIfAbsent(key, s -> value.get());
|
||||
}
|
||||
|
||||
public void setIfAbsentFailable(String key, FailableSupplier<Object> value) throws Exception {
|
||||
if (multiPurposeCache.get(key) == null) {
|
||||
multiPurposeCache.put(key, value.get());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isApplicationInPath(String app) {
|
||||
if (!installedApplications.containsKey(app)) {
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.xpipe.app.util;
|
||||
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.store.FileNames;
|
||||
|
@ -35,12 +36,12 @@ public class ShellTemp {
|
|||
|
||||
var systemTemp = proc.getOsType().getTempDirectory(proc);
|
||||
if (!d.directoryExists(proc, systemTemp).executeAndCheck() || !checkDirectoryPermissions(proc, systemTemp)) {
|
||||
throw new IOException("No permissions to access %s".formatted(systemTemp));
|
||||
throw ErrorEvent.expected(new IOException("No permissions to access %s".formatted(systemTemp)));
|
||||
}
|
||||
|
||||
var home = proc.getOsType().getHomeDirectory(proc);
|
||||
if (!d.directoryExists(proc, home).executeAndCheck() || !checkDirectoryPermissions(proc, home)) {
|
||||
throw new IOException("No permissions to access %s".formatted(home));
|
||||
throw ErrorEvent.expected(new IOException("No permissions to access %s".formatted(home)));
|
||||
}
|
||||
|
||||
// Always delete legacy directory and do not care whether it partially fails
|
||||
|
|
Loading…
Reference in a new issue