Structure relay install transport errors

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-06-20 20:17:07 -07:00
1 parent 2019140832
commit 44dd90fca5
5 files changed
+73 -17

No files matched your search

@@ -7,7 +7,7 @@ import {
SshCommandSpawnError,
SshCommandTimeoutError,
SshHttpBridgeError,
SshPasswordPromptError,
SshPasswordPromptWindowClosedError,
} from "@t3tools/ssh/errors";
import * as Cause from "effect/Cause";
import * as Effect from "effect/Effect";
@@ -62,8 +62,8 @@ describe("SSH environment IPC", () => {
requestId: "prompt-1",
destination: "[email protected]",
});
const cause = new SshPasswordPromptError({
message: promptCause.message,
const cause = new SshPasswordPromptWindowClosedError({
destination: promptCause.destination,
cause: promptCause,
});
const layer = Layer.succeed(
+18 -11
View File
@@ -30,6 +30,7 @@ import {
SshCommandExecutionError,
SshCommandSpawnError,
SshHttpBridgeError,
type SshPasswordPromptError,
SshTunnelMonitorError,
SshTunnelSpawnError,
} from "@t3tools/ssh/errors";
@@ -63,6 +64,19 @@ const desktopSshPasswordPromptCancellationReasons = {
DesktopSshPromptTimedOutError: "timed-out",
} as const;
function handleDesktopSshPasswordPromptCancellation(error: SshPasswordPromptError) {
return DesktopSshEnvironment.isDesktopSshPasswordPromptCancellation(error)
? Effect.succeed(
new DesktopSshPasswordPromptCancellationError({
reason: desktopSshPasswordPromptCancellationReasons[error.cause._tag],
requestId: error.cause.requestId,
destination: error.cause.destination,
cause: error,
}),
)
: Effect.fail(error);
}
const isEnvironmentAuthInvalidError = Schema.is(EnvironmentAuthInvalidError);
const isEnvironmentInternalError = Schema.is(EnvironmentInternalError);
const isEnvironmentOperationForbiddenError = Schema.is(EnvironmentOperationForbiddenError);
@@ -166,17 +180,10 @@ export const ensureSshEnvironment = DesktopIpc.makeIpcMethod({
const sshEnvironment = yield* DesktopSshEnvironment.DesktopSshEnvironment;
return yield* sshEnvironment.ensureEnvironment(target, options).pipe(
Effect.catchTags({
SshPasswordPromptError: (error) =>
DesktopSshEnvironment.isDesktopSshPasswordPromptCancellation(error)
? Effect.succeed(
new DesktopSshPasswordPromptCancellationError({
reason: desktopSshPasswordPromptCancellationReasons[error.cause._tag],
requestId: error.cause.requestId,
destination: error.cause.destination,
cause: error,
}),
)
: Effect.fail(error),
SshPasswordPromptCancelledError: handleDesktopSshPasswordPromptCancellation,
SshPasswordPromptTimedOutError: handleDesktopSshPasswordPromptCancellation,
SshPasswordPromptWindowClosedError: handleDesktopSshPasswordPromptCancellation,
SshPasswordPromptServiceStoppedError: handleDesktopSshPasswordPromptCancellation,
}),
Effect.mapError(toDesktopSshIpcPresentationError),
);
+1 -1
View File
@@ -1313,7 +1313,7 @@ const makeWsRpcLayer = (currentSession: EnvironmentAuth.AuthenticatedSession) =>
(error) =>
new RelayClientInstallFailedError({
reason: relayClientInstallFailureReason(error),
message: error.message,
cause: error,
}),
),
Effect.flatMap((status) =>
@@ -0,0 +1,29 @@
import * as Schema from "effect/Schema";
import { describe, expect, it } from "vite-plus/test";
import { RelayClientInstallFailedError } from "./relayClient.ts";
const encodeRelayClientInstallFailedError = Schema.encodeSync(RelayClientInstallFailedError);
const decodeRelayClientInstallFailedError = Schema.decodeUnknownSync(RelayClientInstallFailedError);
describe("RelayClientInstallFailedError", () => {
it("retains its internal cause without serializing it", () => {
const cause = new Error("private download failure");
const error = new RelayClientInstallFailedError({
reason: "download_failed",
cause,
});
const encoded = encodeRelayClientInstallFailedError(error);
const decoded = decodeRelayClientInstallFailedError(encoded);
expect(error.cause).toBe(cause);
expect(error.message).toBe("Relay client installation failed (download_failed).");
expect(encoded).toEqual({
_tag: "RelayClientInstallFailedError",
reason: "download_failed",
});
expect(decoded.cause).toBeUndefined();
expect(decoded.message).toBe("Relay client installation failed (download_failed).");
});
});
+22 -2
View File
@@ -58,6 +58,26 @@ export class RelayClientInstallFailedError extends Schema.TaggedErrorClass<Relay
"RelayClientInstallFailedError",
{
reason: RelayClientInstallFailureReasonSchema,
message: Schema.String,
},
) {}
) {
// `cause` is intentionally retained only on the server-side error instance. It is not part of
// the RPC schema, so internal installation details cannot cross the transport boundary.
// @effect-diagnostics-next-line overriddenSchemaConstructor:off
constructor(props: {
readonly reason: RelayClientInstallFailureReason;
readonly cause?: unknown;
}) {
super({ reason: props.reason });
if (props.cause !== undefined) {
Object.defineProperty(this, "cause", {
value: props.cause,
configurable: true,
writable: true,
});
}
}
override get message(): string {
return `Relay client installation failed (${this.reason}).`;
}
}