Skip to content

Commit 9951253

Browse files
fix(sagemaker): Use SpaceSettingsSummary.AppType instead of App.AppType (#8276)
## Problem - Fixes crash when connecting to spaces that have been stopped for long - The code was incorrectly accessing node.spaceApp.App.AppType, but the App object is undefined for spaces stopped for long as it deletes the App resource . This caused below error ``` Error running command aws.smus.openRemoteConnection: Remote connection failed: Cannot read properties of undefined (reading 'AppType'). This is likely caused by the extension that contributes aws.smus.openRemoteConnection. ``` ## Solution Changed to use node.spaceApp.SpaceSettingsSummary.AppType instead, which - - Is always available (part of space configuration, not runtime state) - Contains the correct AppType value needed for start/stop operations - SpaceSettingsSummary comes from ListSpaces API call and it will always returns SpaceSettingsSummary as part of the SpaceDetails. - AppType is a required field in SpaceSettingsSummary because every SageMaker space must have an application type (JupyterLab or CodeEditor). --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 5b2bc07 commit 9951253

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/core/src/awsService/sagemaker/commands.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export async function stopSpace(
171171
await client.deleteApp({
172172
DomainId: node.spaceApp.DomainId!,
173173
SpaceName: spaceName,
174-
AppType: node.spaceApp.App!.AppType!,
174+
AppType: node.spaceApp.SpaceSettingsSummary!.AppType!,
175175
AppName: node.spaceApp.App?.AppName,
176176
})
177177
} catch (err) {
@@ -319,7 +319,7 @@ async function handleRunningSpaceWithDisabledAccess(
319319
await client.deleteApp({
320320
DomainId: node.spaceApp.DomainId!,
321321
SpaceName: spaceName,
322-
AppType: node.spaceApp.App!.AppType!,
322+
AppType: node.spaceApp.SpaceSettingsSummary!.AppType!,
323323
AppName: node.spaceApp.App?.AppName,
324324
})
325325

@@ -329,7 +329,11 @@ async function handleRunningSpaceWithDisabledAccess(
329329
// Start the space with remote access enabled (skip prompts since user already consented)
330330
await client.startSpace(spaceName, node.spaceApp.DomainId!, true)
331331
await tryRefreshNode(node)
332-
await client.waitForAppInService(node.spaceApp.DomainId!, spaceName, node.spaceApp.App!.AppType!)
332+
await client.waitForAppInService(
333+
node.spaceApp.DomainId!,
334+
spaceName,
335+
node.spaceApp.SpaceSettingsSummary!.AppType!
336+
)
333337
await tryRemoteConnection(node, ctx, progress)
334338
} catch (err: any) {
335339
// Handle user declining instance type upgrade
@@ -369,7 +373,11 @@ async function handleStoppedSpace(
369373
},
370374
async (progress) => {
371375
progress.report({ message: 'Starting the space' })
372-
await client.waitForAppInService(node.spaceApp.DomainId!, spaceName, node.spaceApp.App!.AppType!)
376+
await client.waitForAppInService(
377+
node.spaceApp.DomainId!,
378+
spaceName,
379+
node.spaceApp.SpaceSettingsSummary!.AppType!
380+
)
373381
await tryRemoteConnection(node, ctx, progress)
374382
}
375383
)

packages/core/src/test/awsService/sagemaker/commands.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe('SageMaker Commands', () => {
5959
AppName: 'default',
6060
},
6161
SpaceSettingsSummary: {
62+
AppType: 'JupyterLab',
6263
RemoteAccess: 'DISABLED',
6364
},
6465
},

0 commit comments

Comments
 (0)