Skip to content

Commit e78b9a2

Browse files
authored
fix(amazonq): "failed to run command" #6982
This command is called frequently and the command or related vscode "view" may not exist yet early in the extension startup/lifecycle.
1 parent 46d475e commit e78b9a2

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
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": "\"failed to run command\" error"
4+
}

packages/amazonq/src/lsp/chat/commands.ts

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

6-
import * as vscode from 'vscode'
76
import { Commands, globals } from 'aws-core-vscode/shared'
87
import { window } from 'vscode'
98
import { AmazonQChatViewProvider } from './webviewProvider'
@@ -74,6 +73,6 @@ function registerGenericCommand(commandName: string, genericCommand: string, pro
7473
* Instead, we just create our own as a temporary solution
7574
*/
7675
async function focusAmazonQPanel() {
77-
await vscode.commands.executeCommand('aws.amazonq.AmazonQChatView.focus')
78-
await vscode.commands.executeCommand('aws.amazonq.AmazonCommonAuth.focus')
76+
await Commands.tryExecute('aws.amazonq.AmazonQChatView.focus')
77+
await Commands.tryExecute('aws.amazonq.AmazonCommonAuth.focus')
7978
}

packages/core/src/amazonqFeatureDev/controllers/chat/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { AuthUtil } from '../../../codewhisperer/util/authUtil'
4242
import { AuthController } from '../../../amazonq/auth/controller'
4343
import { getLogger } from '../../../shared/logger/logger'
4444
import { submitFeedback } from '../../../feedback/vue/submitFeedback'
45-
import { placeholder } from '../../../shared/vscode/commands2'
45+
import { Commands, placeholder } from '../../../shared/vscode/commands2'
4646
import { EditorContentController } from '../../../amazonq/commons/controllers/contentController'
4747
import { openUrl } from '../../../shared/utilities/vsCodeUtils'
4848
import { checkForDevFile, getPathsFromZipFilePath } from '../../../amazonq/util/files'
@@ -579,7 +579,7 @@ export class FeatureDevController {
579579
open
580580
)
581581
if (resp === open) {
582-
await vscode.commands.executeCommand('aws.amazonq.AmazonQChatView.focus')
582+
await Commands.tryExecute('aws.amazonq.AmazonQChatView.focus')
583583
// TODO add focusing on the specific tab once that's implemented
584584
}
585585
}

packages/core/src/codewhispererChat/commands/registerCommands.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { commandPalette } from '../../codewhisperer/commands/types'
77
import { CodeScanIssue } from '../../codewhisperer/models/model'
88
import { Commands, VsCodeCommandArg, placeholder } from '../../shared/vscode/commands2'
99
import { ChatControllerMessagePublishers } from '../controllers/chat/controller'
10-
import vscode from 'vscode'
1110

1211
/**
1312
* Opens the Amazon Q panel, showing the correct View that should
@@ -25,8 +24,8 @@ export const focusAmazonQPanel = Commands.declare(
2524
* So when we try to focus the following Views, only one will show depending
2625
* on the context.
2726
*/
28-
await vscode.commands.executeCommand('aws.amazonq.AmazonQChatView.focus')
29-
await vscode.commands.executeCommand('aws.amazonq.AmazonCommonAuth.focus')
27+
await Commands.tryExecute('aws.amazonq.AmazonQChatView.focus')
28+
await Commands.tryExecute('aws.amazonq.AmazonCommonAuth.focus')
3029
}
3130
)
3231

0 commit comments

Comments
 (0)