@@ -26,7 +26,6 @@ import {
2626} from "@t3tools/contracts" ;
2727import { SshHttpBridgeError } from "@t3tools/ssh/errors" ;
2828import { resolveLoopbackSshHttpBaseUrl } from "@t3tools/ssh/tunnel" ;
29- import * as Data from "effect/Data" ;
3029import * as Effect from "effect/Effect" ;
3130import * as Schema from "effect/Schema" ;
3231
@@ -35,10 +34,12 @@ import * as DesktopIpc from "../DesktopIpc.ts";
3534import * as DesktopSshEnvironment from "../../ssh/DesktopSshEnvironment.ts" ;
3635import * as DesktopSshPasswordPrompts from "../../ssh/DesktopSshPasswordPrompts.ts" ;
3736
38- type DesktopSshEnvironmentRequestOperation =
39- | "fetch-environment-descriptor"
40- | "bootstrap-bearer-session"
41- | "fetch-session-state" ;
37+ const DesktopSshEnvironmentRequestOperation = Schema . Literals ( [
38+ "fetch-environment-descriptor" ,
39+ "bootstrap-bearer-session" ,
40+ "fetch-session-state" ,
41+ ] ) ;
42+ type DesktopSshEnvironmentRequestOperation = typeof DesktopSshEnvironmentRequestOperation . Type ;
4243
4344type DesktopSshEnvironmentRequestCause = RemoteEnvironmentAuthError | SshHttpBridgeError ;
4445
@@ -47,12 +48,13 @@ const isEnvironmentInternalError = Schema.is(EnvironmentInternalError);
4748const isEnvironmentOperationForbiddenError = Schema . is ( EnvironmentOperationForbiddenError ) ;
4849const isEnvironmentRequestInvalidError = Schema . is ( EnvironmentRequestInvalidError ) ;
4950const isEnvironmentScopeRequiredError = Schema . is ( EnvironmentScopeRequiredError ) ;
51+ const isRemoteEnvironmentAuthUndeclaredStatusError = Schema . is (
52+ RemoteEnvironmentAuthUndeclaredStatusError ,
53+ ) ;
54+ const isSshHttpBridgeError = Schema . is ( SshHttpBridgeError ) ;
5055
5156function readSshHttpStatus ( cause : DesktopSshEnvironmentRequestCause ) : number | null {
52- if (
53- cause instanceof RemoteEnvironmentAuthUndeclaredStatusError ||
54- cause instanceof SshHttpBridgeError
55- ) {
57+ if ( isRemoteEnvironmentAuthUndeclaredStatusError ( cause ) || isSshHttpBridgeError ( cause ) ) {
5658 return cause . status ?? null ;
5759 }
5860 if ( isEnvironmentRequestInvalidError ( cause ) ) {
@@ -73,13 +75,14 @@ function readSshHttpStatus(cause: DesktopSshEnvironmentRequestCause): number | n
7375 return null ;
7476}
7577
76- export class DesktopSshEnvironmentRequestError extends Data . TaggedError (
78+ export class DesktopSshEnvironmentRequestError extends Schema . TaggedError < DesktopSshEnvironmentRequestError > ( ) (
7779 "DesktopSshEnvironmentRequestError" ,
78- ) < {
79- readonly operation : DesktopSshEnvironmentRequestOperation ;
80- readonly cause : DesktopSshEnvironmentRequestCause ;
81- readonly sshHttpStatus : number | null ;
82- } > {
80+ {
81+ operation : DesktopSshEnvironmentRequestOperation ,
82+ cause : Schema . Defect ( ) ,
83+ sshHttpStatus : Schema . NullOr ( Schema . Number ) ,
84+ } ,
85+ ) {
8386 // The web client matches "[ssh_http:500]" to explain version-skewed SSH pairing.
8487 override get message ( ) {
8588 const prefix = this . sshHttpStatus === null ? "" : `[ssh_http:${ this . sshHttpStatus } ] ` ;
0 commit comments