Skip to content

Commit 81b90de

Browse files
committed
fix(cloudformation): Fix duplicate stack events
Overwrite events if no nextToken exists to prevent duplication. Based on changes from PR #178.
1 parent b4c0086 commit 81b90de

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

packages/core/src/awsService/cloudformation/ui/stackEventsWebviewProvider.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,17 @@ export class StackEventsWebviewProvider implements WebviewViewProvider, Disposab
5757
this.allEvents = []
5858
this.currentPage = 0
5959
this.nextToken = undefined
60-
await this.loadEvents()
60+
61+
try {
62+
const result = await this.client.sendRequest(GetStackEventsRequest, {
63+
stackName: this.stackName,
64+
})
65+
this.allEvents = result.events
66+
this.nextToken = result.nextToken
67+
} catch (error) {
68+
this.renderError(`Failed to load events: ${extractErrorMessage(error)}`)
69+
}
70+
6171
this.render()
6272
this.startAutoRefresh()
6373
}
@@ -99,7 +109,7 @@ export class StackEventsWebviewProvider implements WebviewViewProvider, Disposab
99109
}
100110

101111
private async loadEvents(): Promise<void> {
102-
if (!this.stackName) {
112+
if (!this.stackName || !this.nextToken) {
103113
return
104114
}
105115

@@ -128,10 +138,12 @@ export class StackEventsWebviewProvider implements WebviewViewProvider, Disposab
128138
})
129139

130140
if (result.gapDetected) {
131-
this.allEvents = []
141+
const initialResult = await this.client.sendRequest(GetStackEventsRequest, {
142+
stackName: this.stackName,
143+
})
144+
this.allEvents = initialResult.events
145+
this.nextToken = initialResult.nextToken
132146
this.currentPage = 0
133-
this.nextToken = undefined
134-
await this.loadEvents()
135147
this.render('Event history reloaded due to high activity')
136148
} else if (result.events.length > 0) {
137149
this.allEvents.unshift(...result.events)

0 commit comments

Comments
 (0)