Skip to content

Commit 37b6592

Browse files
authored
fix(startup): Q may fail if Toolkit fails aws#5731
Problem: If Toolkit fails to start, then Q will also fail to start: 2024-10-01 09:56:13.188 [error] aws.amazonq.refreshConnectionCallback: [ [TypeError: Cannot read properties of undefined (reading 'getApi') at c:\…\dist\src\extensionNode.js:6093:284 Solution: Check for undefined `exports`.
1 parent 13282a0 commit 37b6592

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
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": "Amazon Q extension may fail to start if AWS Toolkit extension fails to start"
4+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export const registerToolkitApiCallback = Commands.declare(
462462
} else if (isExtensionActive(VSCODE_EXTENSION_ID.awstoolkit)) {
463463
// when this command is executed by Amazon Q activation
464464
const toolkitExt = vscode.extensions.getExtension(VSCODE_EXTENSION_ID.awstoolkit)
465-
_toolkitApi = toolkitExt?.exports.getApi(VSCODE_EXTENSION_ID.amazonq)
465+
_toolkitApi = toolkitExt?.exports?.getApi(VSCODE_EXTENSION_ID.amazonq)
466466
}
467467
if (_toolkitApi) {
468468
registerToolkitApiCallbackOnce()

packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class AmazonQLoginWebview extends CommonAuthWebview {
4545
}
4646
await activateExtension(VSCODE_EXTENSION_ID.awstoolkit)
4747
const toolkitExt = vscode.extensions.getExtension(VSCODE_EXTENSION_ID.awstoolkit)
48-
const importedApi = toolkitExt?.exports.getApi(VSCODE_EXTENSION_ID.amazonq)
48+
const importedApi = toolkitExt?.exports?.getApi(VSCODE_EXTENSION_ID.amazonq)
4949
if (importedApi && 'listConnections' in importedApi) {
5050
return ((await importedApi?.listConnections()) as AwsConnection[]).filter(
5151
// No need to display Builder ID as an existing connection,

packages/core/src/test/shared/credentials/userCredentialsUtils.test.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
2121
import { getConfigFilename, getCredentialsFilename } from '../../../auth/credentials/sharedCredentialsFile'
2222
import { fs } from '../../../shared'
2323

24-
/** Async version of "doesNotThrow" */
25-
async function assertDoesNotThrow(fn: () => Promise<void>): Promise<void> {
26-
try {
27-
await fn()
28-
} catch (err) {
29-
assert.fail(`Provided function threw error ${err}`)
30-
}
31-
}
32-
3324
describe('UserCredentialsUtils', function () {
3425
let tempFolder: string
3526
let defaultConfigFileName: string
@@ -151,8 +142,8 @@ describe('UserCredentialsUtils', function () {
151142
`creds.secretKey: "${profile.aws_access_key_id}" !== "${creds.secretKey}"`
152143
)
153144

154-
await assertDoesNotThrow(async () => await fs.checkPerms(credentialsFilename, 'r--'))
155-
await assertDoesNotThrow(async () => await fs.checkPerms(credentialsFilename, '-w-'))
145+
await assert.doesNotReject(async () => await fs.checkPerms(credentialsFilename, 'r--'))
146+
await assert.doesNotReject(async () => await fs.checkPerms(credentialsFilename, '-w-'))
156147
})
157148
})
158149

0 commit comments

Comments
 (0)