Skip to content

Commit 83e9781

Browse files
committed
throw error if node is not in map
1 parent 699919d commit 83e9781

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/core/src/awsService/ec2/explorer/ec2ParentNode.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,18 @@ export class Ec2ParentNode extends AWSTreeNodeBase {
5252
)
5353
}
5454

55+
public getInstanceNode(instanceId: string): Ec2InstanceNode {
56+
const childNode = this.ec2InstanceNodes.get(instanceId)
57+
if (childNode) {
58+
return childNode
59+
} else {
60+
throw new Error(`Node with id ${instanceId} not found`)
61+
}
62+
}
63+
5564
private async updatePendingNodes() {
5665
for (const instanceId of this.pollingSet.values()) {
57-
const childNode = this.ec2InstanceNodes.get(instanceId)!
66+
const childNode = this.getInstanceNode(instanceId)
5867
await this.updatePendingNode(childNode)
5968
}
6069
}

packages/core/src/test/awsService/ec2/explorer/ec2ParentNode.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,23 @@ describe('ec2ParentNode', function () {
182182
sinon.assert.called(refreshStub)
183183
statusUpdateStub.restore()
184184
})
185+
186+
it('returns the node when in the map', async function () {
187+
const instances = [{ Name: 'firstOne', InstanceId: 'node1', LastSeenStatus: 'pending' }]
188+
189+
getInstanceStub.resolves(mapToInstanceCollection(instances))
190+
await testNode.updateChildren()
191+
const node = testNode.getInstanceNode('node1')
192+
assert.strictEqual(node.InstanceId, instances[0].InstanceId)
193+
getInstanceStub.restore()
194+
})
195+
196+
it('throws error when node not in map', async function () {
197+
const instances = [{ Name: 'firstOne', InstanceId: 'node1', LastSeenStatus: 'pending' }]
198+
199+
getInstanceStub.resolves(mapToInstanceCollection(instances))
200+
await testNode.updateChildren()
201+
assert.throws(() => testNode.getInstanceNode('node2'))
202+
getInstanceStub.restore()
203+
})
185204
})

0 commit comments

Comments
 (0)