@@ -18,6 +18,8 @@ import * as Schema from "effect/Schema";
1818import { useState } from "react" ;
1919
2020import { toastManager } from "../components/ui/toast" ;
21+ import { stackedThreadToast } from "../components/ui/toastHelpers" ;
22+ import { relayFailureReason } from "./relayFailureReason" ;
2123import { relayEnvironmentDiscovery } from "../state/relay" ;
2224import { readEnvironmentScope } from "../state/session" ;
2325import { useAtomCommand } from "../state/use-atom-command" ;
@@ -51,6 +53,7 @@ function isManagedTunnelActive(
5153}
5254
5355const isManagedRelayRequestFailedError = Schema . is ( ManagedRelay . ManagedRelayRequestFailedError ) ;
56+ const isManagedRelayClientError = Schema . is ( ManagedRelay . ManagedRelayClientError ) ;
5457
5558/** The account's tunnel cap when the relay refused a new tunnel for being at it. */
5659function tunnelLimitFromLinkFailure ( cause : unknown ) : number | null {
@@ -84,24 +87,28 @@ export function useCloudLinkController(environmentId: EnvironmentId | null) {
8487 const [ operationError , setOperationError ] = useState < string | null > ( null ) ;
8588 const [ tunnelLimit , setTunnelLimit ] = useState < number | null > ( null ) ;
8689
87- const reportUpdateFailure = ( cause : unknown ) => {
90+ const reportUpdateFailure = ( cause : unknown , reason ?: string ) => {
8891 const message = cause instanceof Error ? cause . message : "Could not update T3 Connect access." ;
8992 const traceId = findErrorTraceId ( cause ) ;
9093 console . error ( "[t3-connect] Could not update T3 Connect" , { message, traceId, cause } ) ;
9194 setOperationError ( traceId ? `${ message } Trace ID: ${ traceId } ` : message ) ;
92- toastManager . add ( {
93- type : "error" ,
94- title : "Could not update T3 Connect" ,
95- description : message ,
96- data : traceId
97- ? {
98- secondaryActionProps : {
99- children : "Copy trace ID" ,
100- onClick : ( ) => void navigator . clipboard ?. writeText ( traceId ) ,
101- } ,
102- }
103- : undefined ,
104- } ) ;
95+ toastManager . add (
96+ stackedThreadToast ( {
97+ type : "error" ,
98+ title : "Could not update T3 Connect" ,
99+ description : reason ?? relayFailureReason ( cause ) ?? message ,
100+ ...( traceId
101+ ? {
102+ actionProps : {
103+ children : "Copy trace ID" ,
104+ onClick : ( ) => void navigator . clipboard ?. writeText ( traceId ) ,
105+ } ,
106+ actionVariant : "outline" ,
107+ }
108+ : { } ) ,
109+ data : { hideCopyButton : true } ,
110+ } ) ,
111+ ) ;
105112 } ;
106113
107114 const linkData = cloudLinkState . data ;
@@ -157,9 +164,19 @@ export function useCloudLinkController(environmentId: EnvironmentId | null) {
157164 refreshManagedTunnelUsage ( ) ;
158165 if ( unlinkResult . _tag === "Failure" ) {
159166 if ( ! isAtomCommandInterrupted ( unlinkResult ) ) {
160- reportUpdateFailure ( squashAtomCommandFailure ( unlinkResult ) ) ;
167+ const cause = squashAtomCommandFailure ( unlinkResult ) ;
168+ // Only the relay delete fails with a relay error, and it runs after the local unlink.
169+ const relayKeptLink =
170+ isCloudEnvironmentLinkError ( cause ) && isManagedRelayClientError ( cause . cause ) ;
171+ reportUpdateFailure (
172+ cause ,
173+ relayKeptLink
174+ ? "Disconnected here, but T3 Connect still lists it. Remove it in Account."
175+ : undefined ,
176+ ) ;
161177 }
162178 cloudLinkState . refresh ( ) ;
179+ await refreshRelayEnvironments ( ) ;
163180 return false ;
164181 }
165182 } else {
0 commit comments