Shell error handling fixes

This commit is contained in:
crschnick 2024-03-05 21:50:24 +00:00
parent 73efb183e7
commit 9abd19483f
10 changed files with 32 additions and 15 deletions

View file

@ -31,7 +31,7 @@ public interface BrowserAction {
.orElseThrow(); .orElseThrow();
} }
default void init(OpenFileSystemModel model) {} default void init(OpenFileSystemModel model) throws Exception {}
default String getProFeatureId() { default String getProFeatureId() {
return null; return null;

View file

@ -239,7 +239,8 @@ public class AppSocketServer {
} }
} catch (SocketException ex) { } catch (SocketException ex) {
// Omit it, as this might happen often // 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) { } catch (Throwable ex) {
ErrorEvent.fromThrowable(ex).build().handle(); ErrorEvent.fromThrowable(ex).build().handle();
} finally { } finally {

View file

@ -26,7 +26,7 @@ public interface ActionProvider {
} }
} }
default void init() {} default void init() throws Exception {}
default String getId() { default String getId() {
return null; return null;

View file

@ -39,8 +39,7 @@ public class EventHandlerImpl extends EventHandler {
// Don't block shutdown // Don't block shutdown
if (OperationMode.isInShutdown()) { if (OperationMode.isInShutdown()) {
SentryErrorHandler.getInstance().handle(ee); handleOnShutdown(ee);
handle(fromErrorEvent(ee));
return; return;
} }
@ -51,6 +50,11 @@ public class EventHandlerImpl extends EventHandler {
} }
} }
private void handleOnShutdown(ErrorEvent ee) {
ErrorAction.ignore().handle(ee);
handle(fromErrorEvent(ee));
}
@Override @Override
public void modify(ErrorEvent ee) { public void modify(ErrorEvent ee) {
if (AppLogs.get() != null && AppLogs.get().getSessionLogsDirectory() != null) { if (AppLogs.get() != null && AppLogs.get().getSessionLogsDirectory() != null) {

View file

@ -36,6 +36,7 @@ public class GuiErrorHandler extends GuiErrorHandlerBase implements ErrorHandler
if (lex.isPresent()) { if (lex.isPresent()) {
LicenseProvider.get().showLicenseAlert(lex.get()); LicenseProvider.get().showLicenseAlert(lex.get());
event.setShouldSendDiagnostics(true); event.setShouldSendDiagnostics(true);
event.clearAttachments();
ErrorAction.ignore().handle(event); ErrorAction.ignore().handle(event);
} else { } else {
ErrorHandlerComp.showAndTryWait(event, true); ErrorHandlerComp.showAndTryWait(event, true);

View file

@ -141,7 +141,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
} }
@Override @Override
protected CommandBuilder toCommand(LaunchConfiguration configuration) { protected CommandBuilder toCommand(LaunchConfiguration configuration) throws Exception {
// A weird behavior in Windows Terminal causes the trailing // A weird behavior in Windows Terminal causes the trailing
// backslash of a filepath to escape the closing quote in the title argument // backslash of a filepath to escape the closing quote in the title argument
// So just remove that slash // So just remove that slash
@ -894,6 +894,6 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
launch(configuration.getColoredTitle(), args); launch(configuration.getColoredTitle(), args);
} }
protected abstract CommandBuilder toCommand(LaunchConfiguration configuration); protected abstract CommandBuilder toCommand(LaunchConfiguration configuration) throws Exception;
} }
} }

View file

@ -19,8 +19,9 @@ public class LocalShell {
} }
public static ShellControl getLocalPowershell() throws Exception { public static ShellControl getLocalPowershell() throws Exception {
if (ShellDialects.isPowershell(getShell())) { var s = getShell();
return local; if (ShellDialects.isPowershell(s)) {
return s;
} }
if (localPowershell == null) { if (localPowershell == null) {
@ -29,18 +30,18 @@ public class LocalShell {
.subShell(ShellDialects.POWERSHELL) .subShell(ShellDialects.POWERSHELL)
.start(); .start();
} }
return localPowershell; return localPowershell.start();
} }
public static boolean isLocalShellInitialized() { public static boolean isLocalShellInitialized() {
return local != null; return local != null;
} }
public static ShellControl getShell() { public static ShellControl getShell() throws Exception {
if (local == null) { if (local == null) {
throw new IllegalStateException("Local shell not initialized yet"); throw new IllegalStateException("Local shell not initialized yet");
} }
return local; return local.start();
} }
} }

View file

@ -133,7 +133,9 @@ public class ScanAlert {
} }
}); });
} finally { } finally {
shellControl.close(); if (shellControl != null) {
shellControl.close();
}
shellControl = null; shellControl = null;
} }
}); });

View file

@ -1,6 +1,7 @@
package io.xpipe.app.util; package io.xpipe.app.util;
import io.xpipe.core.process.ShellControl; import io.xpipe.core.process.ShellControl;
import io.xpipe.core.util.FailableSupplier;
import lombok.Getter; import lombok.Getter;
import java.util.HashMap; import java.util.HashMap;
@ -36,6 +37,12 @@ public class ShellControlCache {
multiPurposeCache.computeIfAbsent(key, s -> value.get()); 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) { public boolean isApplicationInPath(String app) {
if (!installedApplications.containsKey(app)) { if (!installedApplications.containsKey(app)) {
try { try {

View file

@ -1,5 +1,6 @@
package io.xpipe.app.util; package io.xpipe.app.util;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.core.process.OsType; import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellControl; import io.xpipe.core.process.ShellControl;
import io.xpipe.core.store.FileNames; import io.xpipe.core.store.FileNames;
@ -35,12 +36,12 @@ public class ShellTemp {
var systemTemp = proc.getOsType().getTempDirectory(proc); var systemTemp = proc.getOsType().getTempDirectory(proc);
if (!d.directoryExists(proc, systemTemp).executeAndCheck() || !checkDirectoryPermissions(proc, systemTemp)) { 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); var home = proc.getOsType().getHomeDirectory(proc);
if (!d.directoryExists(proc, home).executeAndCheck() || !checkDirectoryPermissions(proc, home)) { 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 // Always delete legacy directory and do not care whether it partially fails