Skip to content

Commit 9b13c5f

Browse files
authored
fix(tests): "rejected promise not handled" (#7403)
## Problem: rejected promise not handled within 1 second: Error: command 'aws.amazonq.focusChat' not found ## Solution: Don't use `void` to ignore rejected promises. --- - 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 fb1dae8 commit 9b13c5f

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

packages/amazonq/src/app/chat/activation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as vscode from 'vscode'
77
import { ExtensionContext } from 'vscode'
88
import { telemetry } from 'aws-core-vscode/telemetry'
99
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
10-
import { Commands, placeholder } from 'aws-core-vscode/shared'
10+
import { Commands, getLogger, placeholder } from 'aws-core-vscode/shared'
1111
import * as amazonq from 'aws-core-vscode/amazonq'
1212

1313
export async function activate(context: ExtensionContext) {
@@ -67,7 +67,9 @@ async function setupAuthNotification() {
6767
const selection = await vscode.window.showWarningMessage('Start using Amazon Q', buttonAction)
6868

6969
if (selection === buttonAction) {
70-
void amazonq.focusAmazonQPanel.execute(placeholder, source)
70+
amazonq.focusAmazonQPanel.execute(placeholder, source).catch((e) => {
71+
getLogger().error('focusAmazonQPanel failed: %s', e)
72+
})
7173
}
7274
}
7375
}

packages/amazonq/src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
166166
// Give time for the extension to finish initializing.
167167
globals.clock.setTimeout(async () => {
168168
CommonAuthWebview.authSource = ExtStartUpSources.firstStartUp
169-
void focusAmazonQPanel.execute(placeholder, ExtStartUpSources.firstStartUp)
169+
focusAmazonQPanel.execute(placeholder, ExtStartUpSources.firstStartUp).catch((e) => {
170+
getLogger().error('focusAmazonQPanel failed: %s', e)
171+
})
170172
}, 1000)
171173
}
172174

packages/core/src/amazonq/auth/controller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { getLogger } from '../../shared/logger/logger'
67
import { reconnect } from '../../codewhisperer/commands/basicCommands'
78
import { amazonQChatSource } from '../../codewhisperer/commands/types'
89
import { focusAmazonQPanel } from '../../codewhispererChat/commands/registerCommands'
@@ -27,7 +28,9 @@ export class AuthController {
2728
}
2829

2930
private handleFullAuth() {
30-
void focusAmazonQPanel.execute(placeholder, 'amazonQChat')
31+
focusAmazonQPanel.execute(placeholder, 'amazonQChat').catch((e) => {
32+
getLogger().error('focusAmazonQPanel failed: %s', e)
33+
})
3134
}
3235

3336
private handleReAuth() {

packages/core/src/codewhisperer/commands/basicCommands.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ export const notifyNewCustomizationsCmd = Commands.declare(
405405
function focusQAfterDelay() {
406406
// this command won't work without a small delay after install
407407
globals.clock.setTimeout(() => {
408-
void focusAmazonQPanel.execute(placeholder, 'startDelay')
408+
focusAmazonQPanel.execute(placeholder, 'startDelay').catch((e) => {
409+
getLogger().error('focusAmazonQPanel failed: %s', e)
410+
})
409411
}, 1000)
410412
}
411413

@@ -597,7 +599,10 @@ export const signoutCodeWhisperer = Commands.declare(
597599
(auth: AuthUtil) => async (_: VsCodeCommandArg, source: CodeWhispererSource) => {
598600
await auth.secondaryAuth.deleteConnection()
599601
SecurityIssueTreeViewProvider.instance.refresh()
600-
return focusAmazonQPanel.execute(placeholder, source)
602+
return focusAmazonQPanel.execute(placeholder, source).catch((e) => {
603+
getLogger().error('focusAmazonQPanel failed: %s', e)
604+
return undefined
605+
})
601606
}
602607
)
603608

packages/core/src/codewhisperer/ui/codeWhispererNodes.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { AuthUtil } from '../util/authUtil'
2828
import { submitFeedback } from '../../feedback/vue/submitFeedback'
2929
import { focusAmazonQPanel } from '../../codewhispererChat/commands/registerCommands'
3030
import { isWeb } from '../../shared/extensionGlobals'
31+
import { getLogger } from '../../shared/logger/logger'
3132

3233
export function createAutoSuggestions(running: boolean): DataQuickPickItem<'autoSuggestions'> {
3334
const labelResume = localize('AWS.codewhisperer.resumeCodeWhispererNode.label', 'Resume Auto-Suggestions')
@@ -238,7 +239,10 @@ export function switchToAmazonQNode(): DataQuickPickItem<'openChatPanel'> {
238239
data: 'openChatPanel',
239240
label: 'Open Chat Panel',
240241
iconPath: getIcon('vscode-comment'),
241-
onClick: () => focusAmazonQPanel.execute(placeholder, 'codewhispererQuickPick'),
242+
onClick: () =>
243+
focusAmazonQPanel.execute(placeholder, 'codewhispererQuickPick').catch((e) => {
244+
getLogger().error('focusAmazonQPanel failed: %s', e)
245+
}),
242246
}
243247
}
244248

@@ -247,7 +251,9 @@ export function createSignIn(): DataQuickPickItem<'signIn'> {
247251
const icon = getIcon('vscode-account')
248252

249253
let onClick = () => {
250-
void focusAmazonQPanel.execute(placeholder, 'codewhispererQuickPick')
254+
focusAmazonQPanel.execute(placeholder, 'codewhispererQuickPick').catch((e) => {
255+
getLogger().error('focusAmazonQPanel failed: %s', e)
256+
})
251257
}
252258
if (isWeb()) {
253259
// TODO: nkomonen, call a Command instead

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ export class AuthUtil {
267267
} catch (err) {
268268
if (err instanceof ProfileNotFoundError) {
269269
// Expected that connection would be deleted by conn.getToken()
270-
void focusAmazonQPanel.execute(placeholder, 'profileNotFoundSignout')
270+
focusAmazonQPanel.execute(placeholder, 'profileNotFoundSignout').catch((e) => {
271+
getLogger().error('focusAmazonQPanel failed: %s', e)
272+
})
271273
}
272274
throw err
273275
}

0 commit comments

Comments
 (0)