Skip to content

Commit d40367b

Browse files
authored
AWS Explorer now shows a node indicating when CloudFormation Stacks cannot be found in a region (#815)
1 parent 61bb331 commit d40367b

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "AWS Explorer now shows a node indicating when CloudFormation Stacks cannot be found in a region"
4+
}

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"AWS.explorerNode.addRegion.tooltip": "Click to add a region to view functions...",
5151
"AWS.explorerNode.lambda.noFunctions": "[No Functions found]",
5252
"AWS.explorerNode.cloudFormation.noFunctions": "[no functions in this CloudFormation]",
53+
"AWS.explorerNode.cloudformation.noStacks": "[No Stacks found]",
5354
"AWS.explorerNode.cloudFormation.error": "Error loading CloudFormation resources",
5455
"AWS.explorerNode.container.noItems": "[no items]",
5556
"AWS.explorerNode.lambda.retry": "Unable to load Lambda Functions, click here to retry",

src/lambda/explorer/cloudFormationNodes.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,39 @@ import { AWSTreeErrorHandlerNode } from '../../shared/treeview/nodes/awsTreeErro
1616
import { AWSTreeNodeBase } from '../../shared/treeview/nodes/awsTreeNodeBase'
1717
import { ErrorNode } from '../../shared/treeview/nodes/errorNode'
1818
import { PlaceholderNode } from '../../shared/treeview/nodes/placeholderNode'
19+
import { makeChildrenNodes } from '../../shared/treeview/treeNodeUtilities'
1920
import { intersection, toArrayAsync, toMap, toMapAsync, updateInPlace } from '../../shared/utilities/collectionUtils'
2021
import { listCloudFormationStacks, listLambdaFunctions } from '../utils'
2122
import { LambdaFunctionNode } from './lambdaFunctionNode'
2223

2324
export const CONTEXT_VALUE_CLOUDFORMATION_LAMBDA_FUNCTION = 'awsCloudFormationFunctionNode'
2425

25-
export class CloudFormationNode extends AWSTreeErrorHandlerNode {
26+
export class CloudFormationNode extends AWSTreeNodeBase {
2627
private readonly stackNodes: Map<string, CloudFormationStackNode>
2728

2829
public constructor(private readonly regionCode: string) {
2930
super('CloudFormation', vscode.TreeItemCollapsibleState.Collapsed)
3031
this.stackNodes = new Map<string, CloudFormationStackNode>()
3132
}
3233

33-
public async getChildren(): Promise<(CloudFormationStackNode | ErrorNode)[]> {
34-
await this.handleErrorProneOperation(
35-
async () => this.updateChildren(),
36-
localize('AWS.explorerNode.cloudFormation.error', 'Error loading CloudFormation resources')
37-
)
38-
39-
return !!this.errorNode
40-
? [this.errorNode]
41-
: [...this.stackNodes.values()].sort((nodeA, nodeB) => nodeA.stackName.localeCompare(nodeB.stackName))
34+
public async getChildren(): Promise<AWSTreeNodeBase[]> {
35+
return await makeChildrenNodes({
36+
getChildNodes: async () => {
37+
await this.updateChildren()
38+
39+
return [...this.stackNodes.values()]
40+
},
41+
getErrorNode: async (error: Error) =>
42+
new ErrorNode(
43+
this,
44+
error,
45+
localize('AWS.explorerNode.cloudFormation.error', 'Error loading CloudFormation resources')
46+
),
47+
getNoChildrenPlaceholderNode: async () =>
48+
new PlaceholderNode(this, localize('AWS.explorerNode.cloudformation.noStacks', '[No Stacks found]')),
49+
sort: (nodeA: CloudFormationStackNode, nodeB: CloudFormationStackNode) =>
50+
nodeA.stackName.localeCompare(nodeB.stackName)
51+
})
4252
}
4353

4454
public async updateChildren(): Promise<void> {

src/test/lambda/explorer/cloudFormationNodes.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,23 @@ describe('CloudFormationNode', () => {
260260
assert.deepStrictEqual(actualChildOrder, expectedChildOrder, 'Unexpected child sort order')
261261
})
262262

263-
it('handles error', async () => {
263+
it('returns placeholder node if no children are present', async () => {
264+
const cloudFormationClient = makeCloudFormationClient([])
265+
266+
const clientBuilder = {
267+
createCloudFormationClient: sandbox.stub().returns(cloudFormationClient)
268+
}
269+
270+
ext.toolkitClientBuilder = (clientBuilder as any) as ToolkitClientBuilder
271+
272+
const cloudFormationNode = new CloudFormationNode(FAKE_REGION_CODE)
273+
274+
const children = await cloudFormationNode.getChildren()
275+
276+
assertNodeListOnlyContainsPlaceholderNode(children)
277+
})
278+
279+
it('has an error node for a child if an error happens during loading', async () => {
264280
const testNode = new CloudFormationNode(FAKE_REGION_CODE)
265281
sandbox.stub(testNode, 'updateChildren').callsFake(() => {
266282
throw new Error('Update Children error!')

0 commit comments

Comments
 (0)