fix(desktop): preserve structural SSH IPC errors
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
44dd90fca5
commit
9ed4bf4f52
2 files changed
+35
-50
No files matched your search
@@ -5,7 +5,6 @@ import {
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
SshCommandSpawnError,
|
||||
SshCommandTimeoutError,
|
||||
SshHttpBridgeError,
|
||||
SshPasswordPromptWindowClosedError,
|
||||
} from "@t3tools/ssh/errors";
|
||||
@@ -21,9 +20,9 @@ import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
|
||||
|
||||
import {
|
||||
DesktopSshEnvironmentRequestError,
|
||||
disconnectSshEnvironment,
|
||||
ensureSshEnvironment,
|
||||
fetchSshEnvironmentDescriptor,
|
||||
toDesktopSshIpcPresentationError,
|
||||
} from "./sshEnvironment.ts";
|
||||
import * as DesktopSshEnvironment from "../../ssh/DesktopSshEnvironment.ts";
|
||||
import * as DesktopSshPasswordPrompts from "../../ssh/DesktopSshPasswordPrompts.ts";
|
||||
@@ -95,7 +94,7 @@ describe("SSH environment IPC", () => {
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
|
||||
it("presents legacy process causes without weakening structured errors", () => {
|
||||
it.effect("preserves structural SSH errors and exact causes at the IPC boundary", () => {
|
||||
const cause = new Error("ssh executable was not found");
|
||||
const structured = new SshCommandSpawnError({
|
||||
command: "ssh",
|
||||
@@ -103,22 +102,35 @@ describe("SSH environment IPC", () => {
|
||||
target: "devbox",
|
||||
cause,
|
||||
});
|
||||
const target = {
|
||||
alias: "devbox",
|
||||
hostname: "devbox.example.test",
|
||||
username: "developer",
|
||||
port: 22,
|
||||
};
|
||||
const layer = Layer.succeed(
|
||||
DesktopSshEnvironment.DesktopSshEnvironment,
|
||||
DesktopSshEnvironment.DesktopSshEnvironment.of({
|
||||
discoverHosts: () => Effect.die("unexpected host discovery"),
|
||||
ensureEnvironment: () => Effect.fail(structured),
|
||||
disconnectEnvironment: () => Effect.fail(structured),
|
||||
}),
|
||||
);
|
||||
|
||||
const presentation = toDesktopSshIpcPresentationError(structured);
|
||||
assert.equal(structured.message, "Failed to spawn SSH command for devbox.");
|
||||
assert.equal(presentation.message, cause.message);
|
||||
assert.strictEqual(presentation.cause, structured);
|
||||
});
|
||||
|
||||
it("passes structural SSH errors without process causes through the IPC boundary", () => {
|
||||
const structured = new SshCommandTimeoutError({
|
||||
command: "ssh",
|
||||
argumentCount: 0,
|
||||
target: "devbox",
|
||||
timeoutMs: 30_000,
|
||||
});
|
||||
|
||||
assert.strictEqual(toDesktopSshIpcPresentationError(structured), structured);
|
||||
return Effect.gen(function* () {
|
||||
const exits = yield* Effect.all([
|
||||
Effect.exit(ensureSshEnvironment.handler({ target })),
|
||||
Effect.exit(disconnectSshEnvironment.handler(target)),
|
||||
]);
|
||||
for (const exit of exits) {
|
||||
assert(Exit.isFailure(exit));
|
||||
const failure = Cause.findErrorOption(exit.cause);
|
||||
assert(Option.isSome(failure));
|
||||
assert.strictEqual(failure.value, structured);
|
||||
}
|
||||
assert.equal(structured.message, "Failed to spawn SSH command for devbox.");
|
||||
assert.strictEqual(structured.cause, cause);
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
|
||||
it.effect("fetches and decodes the remote environment descriptor", () => {
|
||||
|
||||
@@ -26,14 +26,7 @@ import {
|
||||
AuthSessionState,
|
||||
AuthWebSocketTicketResult,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
SshCommandExecutionError,
|
||||
SshCommandSpawnError,
|
||||
SshHttpBridgeError,
|
||||
type SshPasswordPromptError,
|
||||
SshTunnelMonitorError,
|
||||
SshTunnelSpawnError,
|
||||
} from "@t3tools/ssh/errors";
|
||||
import { SshHttpBridgeError, type SshPasswordPromptError } from "@t3tools/ssh/errors";
|
||||
import { resolveLoopbackSshHttpBaseUrl } from "@t3tools/ssh/tunnel";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schema from "effect/Schema";
|
||||
@@ -83,26 +76,6 @@ const isEnvironmentOperationForbiddenError = Schema.is(EnvironmentOperationForbi
|
||||
const isEnvironmentRequestInvalidError = Schema.is(EnvironmentRequestInvalidError);
|
||||
const isEnvironmentScopeRequiredError = Schema.is(EnvironmentScopeRequiredError);
|
||||
const isSshHttpBridgeError = Schema.is(SshHttpBridgeError);
|
||||
const isSshCausePresentationError = Schema.is(
|
||||
Schema.Union([
|
||||
SshCommandSpawnError,
|
||||
SshCommandExecutionError,
|
||||
SshTunnelSpawnError,
|
||||
SshTunnelMonitorError,
|
||||
]),
|
||||
);
|
||||
|
||||
// Electron only forwards the message from a rejected ipcRenderer.invoke promise. Keep the typed,
|
||||
// structural SSH error intact as the cause for main-process diagnostics while preserving the
|
||||
// actionable process message that the renderer historically presented to the user.
|
||||
export function toDesktopSshIpcPresentationError(
|
||||
error: DesktopSshEnvironment.DesktopSshEnvironmentOperationError,
|
||||
): DesktopSshEnvironment.DesktopSshEnvironmentOperationError | Error {
|
||||
if (isSshCausePresentationError(error) && error.cause instanceof Error) {
|
||||
return new Error(error.cause.message, { cause: error });
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
function readSshHttpStatus(cause: DesktopSshEnvironmentRequestCause): number | null {
|
||||
if (isRemoteEnvironmentAuthUndeclaredStatusError(cause)) {
|
||||
@@ -169,6 +142,9 @@ export const discoverSshHosts = DesktopIpc.makeIpcMethod({
|
||||
}),
|
||||
});
|
||||
|
||||
// Electron forwards only the message from a rejected ipcRenderer.invoke promise to the renderer.
|
||||
// Preserve typed SSH errors at this boundary so that message stays structural while main-process
|
||||
// diagnostics retain the exact cause and error fields.
|
||||
export const ensureSshEnvironment = DesktopIpc.makeIpcMethod({
|
||||
channel: IpcChannels.ENSURE_SSH_ENVIRONMENT_CHANNEL,
|
||||
payload: DesktopSshEnvironmentEnsureInputSchema,
|
||||
@@ -185,7 +161,6 @@ export const ensureSshEnvironment = DesktopIpc.makeIpcMethod({
|
||||
SshPasswordPromptWindowClosedError: handleDesktopSshPasswordPromptCancellation,
|
||||
SshPasswordPromptServiceStoppedError: handleDesktopSshPasswordPromptCancellation,
|
||||
}),
|
||||
Effect.mapError(toDesktopSshIpcPresentationError),
|
||||
);
|
||||
}),
|
||||
});
|
||||
@@ -196,9 +171,7 @@ export const disconnectSshEnvironment = DesktopIpc.makeIpcMethod({
|
||||
result: Schema.Void,
|
||||
handler: Effect.fn("desktop.ipc.sshEnvironment.disconnectEnvironment")(function* (target) {
|
||||
const sshEnvironment = yield* DesktopSshEnvironment.DesktopSshEnvironment;
|
||||
yield* sshEnvironment
|
||||
.disconnectEnvironment(target)
|
||||
.pipe(Effect.mapError(toDesktopSshIpcPresentationError));
|
||||
yield* sshEnvironment.disconnectEnvironment(target);
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user