@@ -193,67 +193,61 @@ export async function openRemoteConnect(
193193 }
194194
195195 const spaceName = node . spaceApp . SpaceName !
196+ await tryRefreshNode ( node )
196197
197- try {
198- await tryRefreshNode ( node )
199-
200- // for Stopped SM spaces - check instance type before showing progress
201- if ( node . getStatus ( ) === 'Stopped' ) {
202- // In case of SMUS, we pass in a SM Client and for SM AI, it creates a new SM Client.
203- const client = sageMakerClient ? sageMakerClient : new SagemakerClient ( node . regionCode )
204-
205- try {
206- await client . startSpace ( spaceName , node . spaceApp . DomainId ! )
207- await tryRefreshNode ( node )
208- const appType = node . spaceApp . SpaceSettingsSummary ?. AppType
209- if ( ! appType ) {
210- throw new ToolkitError (
211- 'AppType is undefined for the selected space. Cannot start remote connection.' ,
212- {
213- code : 'undefinedAppType' ,
214- }
215- )
216- }
217-
218- // Only start showing progress after instance type validation
219- return await vscode . window . withProgress (
198+ // for Stopped SM spaces - check instance type before showing progress
199+ if ( node . getStatus ( ) === 'Stopped' ) {
200+ // In case of SMUS, we pass in a SM Client and for SM AI, it creates a new SM Client.
201+ const client = sageMakerClient ? sageMakerClient : new SagemakerClient ( node . regionCode )
202+
203+ try {
204+ await client . startSpace ( spaceName , node . spaceApp . DomainId ! )
205+ await tryRefreshNode ( node )
206+ const appType = node . spaceApp . SpaceSettingsSummary ?. AppType
207+ if ( ! appType ) {
208+ throw new ToolkitError (
209+ 'AppType is undefined for the selected space. Cannot start remote connection.' ,
220210 {
221- location : vscode . ProgressLocation . Notification ,
222- cancellable : false ,
223- title : `Connecting to ${ spaceName } ` ,
224- } ,
225- async ( progress ) => {
226- progress . report ( { message : 'Starting the space.' } )
227- await client . waitForAppInService ( node . spaceApp . DomainId ! , spaceName , appType )
228- await tryRemoteConnection ( node , ctx , progress )
211+ code : 'undefinedAppType' ,
229212 }
230213 )
231- } catch ( err : any ) {
232- // Ignore InstanceTypeError since it means the user decided not to use an instanceType with more memory
233- // just return without showing progress
234- if ( err . code === InstanceTypeError ) {
235- return
236- }
237- throw new ToolkitError ( `Remote connection failed: ${ ( err as Error ) . message } ` , {
238- cause : err as Error ,
239- code : err . code ,
240- } )
241214 }
242- } else if ( node . getStatus ( ) === 'Running' ) {
243- // For running spaces, show progress
215+
216+ // Only start showing progress after instance type validation
244217 return await vscode . window . withProgress (
245218 {
246219 location : vscode . ProgressLocation . Notification ,
247220 cancellable : false ,
248221 title : `Connecting to ${ spaceName } ` ,
249222 } ,
250223 async ( progress ) => {
224+ progress . report ( { message : 'Starting the space.' } )
225+ await client . waitForAppInService ( node . spaceApp . DomainId ! , spaceName , appType )
251226 await tryRemoteConnection ( node , ctx , progress )
252227 }
253228 )
229+ } catch ( err : any ) {
230+ // Ignore InstanceTypeError since it means the user decided not to use an instanceType with more memory
231+ // just return without showing progress
232+ if ( err . code === InstanceTypeError ) {
233+ return
234+ }
235+ throw new ToolkitError ( `Remote connection failed: ${ ( err as Error ) . message } ` , {
236+ cause : err as Error ,
237+ code : err . code ,
238+ } )
254239 }
255- } catch ( err : any ) {
256- getLogger ( ) . error ( `sm:openRemoteConnect: ${ err } ` )
257- throw err
240+ } else if ( node . getStatus ( ) === 'Running' ) {
241+ // For running spaces, show progress
242+ return await vscode . window . withProgress (
243+ {
244+ location : vscode . ProgressLocation . Notification ,
245+ cancellable : false ,
246+ title : `Connecting to ${ spaceName } ` ,
247+ } ,
248+ async ( progress ) => {
249+ await tryRemoteConnection ( node , ctx , progress )
250+ }
251+ )
258252 }
259253}
0 commit comments