History

Use schema guards for desktop SSH errors

Cursor Agent committed 4 months ago

Commit 7ce32a81 parent b8090463 files · +10 −6Browse files

Unified · Split

3 files
  1. apps/desktop/src/ipc/methods/sshEnvironment.test.ts +4 −1
  2. apps/desktop/src/ipc/methods/sshEnvironment.ts +2 −4
  3. apps/desktop/src/ssh/DesktopSshEnvironment.ts +4 −1
apps/desktop/src/ipc/methods/sshEnvironment.test.ts+4−1
@@ -5,6 +5,7 @@ import * as Effect from "effect/Effect"; · 4 unmodified lines
5import * as Exit from "effect/Exit";5import * as Exit from "effect/Exit";
6import * as Layer from "effect/Layer";6import * as Layer from "effect/Layer";
7import * as Option from "effect/Option";7import * as Option from "effect/Option";
8import * as Schema from "effect/Schema";
8import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";9import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
9 10
10import {11import {
@@ -12,6 +13,8 @@ import { · 1 unmodified line
12 fetchSshEnvironmentDescriptor,13 fetchSshEnvironmentDescriptor,
13} from "./sshEnvironment.ts";14} from "./sshEnvironment.ts";
14 15
16const isSshHttpBridgeError = Schema.is(SshHttpBridgeError);
17
15function jsonResponse(request: HttpClientRequest.HttpClientRequest, body: unknown, status = 200) {18function jsonResponse(request: HttpClientRequest.HttpClientRequest, body: unknown, status = 200) {
16 return HttpClientResponse.fromWeb(19 return HttpClientResponse.fromWeb(
17 request,20 request,
@@ -83,7 +86,7 @@ describe("SSH environment IPC", () => { · 65 unmodified lines
83 86
84 assert.instanceOf(error, DesktopSshEnvironmentRequestError);87 assert.instanceOf(error, DesktopSshEnvironmentRequestError);
85 assert.equal(error.operation, "fetch-environment-descriptor");88 assert.equal(error.operation, "fetch-environment-descriptor");
86 assert.equal(error.cause instanceof SshHttpBridgeError, false);89 assert.equal(isSshHttpBridgeError(error.cause), false);
87 }).pipe(Effect.provide(layer));90 }).pipe(Effect.provide(layer));
88 });91 });
89 92
apps/desktop/src/ipc/methods/sshEnvironment.ts+2−4
@@ -50,12 +50,10 @@ const isEnvironmentInternalError = Schema.is(EnvironmentInternalError); · 49 unmodified lines
50const isEnvironmentOperationForbiddenError = Schema.is(EnvironmentOperationForbiddenError);50const isEnvironmentOperationForbiddenError = Schema.is(EnvironmentOperationForbiddenError);
51const isEnvironmentRequestInvalidError = Schema.is(EnvironmentRequestInvalidError);51const isEnvironmentRequestInvalidError = Schema.is(EnvironmentRequestInvalidError);
52const isEnvironmentScopeRequiredError = Schema.is(EnvironmentScopeRequiredError);52const isEnvironmentScopeRequiredError = Schema.is(EnvironmentScopeRequiredError);
53const isSshHttpBridgeError = Schema.is(SshHttpBridgeError);
53 54
54function readSshHttpStatus(cause: DesktopSshEnvironmentRequestCause): number | null {55function readSshHttpStatus(cause: DesktopSshEnvironmentRequestCause): number | null {
55 if (56 if (cause instanceof RemoteEnvironmentAuthUndeclaredStatusError || isSshHttpBridgeError(cause)) {
56 cause instanceof RemoteEnvironmentAuthUndeclaredStatusError ||
57 cause instanceof SshHttpBridgeError
58 ) {
59 return cause.status ?? null;57 return cause.status ?? null;
60 }58 }
61 if (isEnvironmentRequestInvalidError(cause)) {59 if (isEnvironmentRequestInvalidError(cause)) {
apps/desktop/src/ssh/DesktopSshEnvironment.ts+4−1
@@ -21,6 +21,7 @@ import * as Effect from "effect/Effect"; · 20 unmodified lines
21import * as FileSystem from "effect/FileSystem";21import * as FileSystem from "effect/FileSystem";
22import * as Layer from "effect/Layer";22import * as Layer from "effect/Layer";
23import * as Path from "effect/Path";23import * as Path from "effect/Path";
24import * as Schema from "effect/Schema";
24import * as HttpClient from "effect/unstable/http/HttpClient";25import * as HttpClient from "effect/unstable/http/HttpClient";
25import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";26import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
26 27
@@ -69,6 +70,8 @@ export interface DesktopSshEnvironmentLayerOptions { · 42 unmodified lines
69 readonly resolveCliRunner?: Effect.Effect<SshTunnel.RemoteT3RunnerOptions>;70 readonly resolveCliRunner?: Effect.Effect<SshTunnel.RemoteT3RunnerOptions>;
70}71}
71 72
73const isSshPasswordPromptError = Schema.is(SshPasswordPromptError);
74
72function discoverDesktopSshHostsEffect(input?: { readonly homeDir?: string }) {75function discoverDesktopSshHostsEffect(input?: { readonly homeDir?: string }) {
73 return discoverSshHosts(input ?? {});76 return discoverSshHosts(input ?? {});
74}77}
@@ -77,7 +80,7 @@ export function isDesktopSshPasswordPromptCancellation( · 2 unmodified lines
77 error: unknown,80 error: unknown,
78): error is SshPasswordPromptError {81): error is SshPasswordPromptError {
79 return (82 return (
80 error instanceof SshPasswordPromptError &&83 isSshPasswordPromptError(error) &&
81 DesktopSshPasswordPrompts.isDesktopSshPasswordPromptCancellation(error.cause)84 DesktopSshPasswordPrompts.isDesktopSshPasswordPromptCancellation(error.cause)
82 );85 );
83}86}