Skip to content

Commit 26cd09e

Browse files
dhasani23David Hasani
andauthored
fix(amazonq): show error messages in chat and match with IntelliJ (aws#4715)
* fix(amazonq): show error messages in chat and match with IntelliJ * revert accidental deletion: * remove unused button * small string changes * fix lint issues * Update transformByQ.test.ts --------- Co-authored-by: David Hasani <[email protected]>
1 parent b2969ff commit 26cd09e

File tree

14 files changed

+301
-248
lines changed

14 files changed

+301
-248
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 Code Transformation: show error messages in chat"
4+
}

packages/core/src/amazonqGumby/activation.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { TransformationHubViewProvider } from '../codewhisperer/service/transfor
99
import { ExtContext } from '../shared/extensions'
1010
import { stopTransformByQ } from '../codewhisperer/commands/startTransformByQ'
1111
import { transformByQState } from '../codewhisperer/models/model'
12-
import * as CodeWhispererConstants from '../codewhisperer/models/constants'
1312
import { ProposedTransformationExplorer } from '../codewhisperer/service/transformByQ/transformationResultsViewProvider'
1413
import { codeTransformTelemetryState } from './telemetry/codeTransformTelemetryState'
1514
import { telemetry } from '../shared/telemetry/telemetry'
@@ -52,8 +51,6 @@ export async function activate(context: ExtContext) {
5251
Commands.register('aws.amazonq.stopTransformationInHub', async (cancelSrc: CancelActionPositions) => {
5352
if (transformByQState.isRunning()) {
5453
void stopTransformByQ(transformByQState.getJobId(), cancelSrc)
55-
} else {
56-
void vscode.window.showInformationMessage(CodeWhispererConstants.noOngoingJobMessage)
5754
}
5855
}),
5956

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
validateCanCompileProject,
2525
} from '../../../codewhisperer/commands/startTransformByQ'
2626
import { JDKVersion, TransformationCandidateProject, transformByQState } from '../../../codewhisperer/models/model'
27+
import * as CodeWhispererConstants from '../../../codewhisperer/models/constants'
2728
import { JavaHomeNotSetError, NoJavaProjectsFoundError, NoMavenJavaProjectsFoundError } from '../../errors'
2829
import MessengerUtils, { ButtonActions, GumbyCommands } from './messenger/messengerUtils'
2930
import { CancelActionPositions } from '../../telemetry/codeTransformTelemetry'
@@ -213,7 +214,7 @@ export class GumbyController {
213214
await this.initiateTransformationOnProject(message)
214215
break
215216
case ButtonActions.CANCEL_TRANSFORMATION_FORM:
216-
this.messenger.sendJobFinishedMessage(message.tabId, true)
217+
this.messenger.sendJobFinishedMessage(message.tabId, CodeWhispererConstants.jobCancelledChatMessage)
217218
break
218219
case ButtonActions.VIEW_TRANSFORMATION_HUB:
219220
await vscode.commands.executeCommand(GumbyCommands.FOCUS_TRANSFORMATION_HUB)
@@ -309,10 +310,10 @@ export class GumbyController {
309310
await this.prepareProjectForSubmission(message)
310311
}
311312

312-
private async transformationFinished(tabID: string, jobStatus: string = '') {
313+
private async transformationFinished(data: { message: string; tabID: string }) {
313314
this.sessionStorage.getSession().conversationState = ConversationState.IDLE
314315
// at this point job is either completed, partially_completed, cancelled, or failed
315-
this.messenger.sendJobFinishedMessage(tabID, false)
316+
this.messenger.sendJobFinishedMessage(data.tabID, data.message)
316317
}
317318

318319
private async processHumanChatMessage(data: { message: string; tabID: string }) {

packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { AuthFollowUpType, expiredText, enableQText, reauthenticateText } from '
1212
import { ChatItemType } from '../../../../amazonqFeatureDev/models'
1313
import { JDKVersion, TransformationCandidateProject } from '../../../../codewhisperer/models/model'
1414
import { FeatureAuthState } from '../../../../codewhisperer/util/authUtil'
15+
import * as CodeWhispererConstants from '../../../../codewhisperer/models/constants'
1516
import {
1617
AppToWebViewMessageDispatcher,
1718
AsyncEventProgressMessage,
@@ -35,7 +36,6 @@ export type StaticTextResponseType =
3536

3637
export type ErrorTextResponseType =
3738
| 'no-project-found'
38-
| 'no-workspace-open'
3939
| 'no-java-project-found'
4040
| 'no-maven-java-project-found'
4141
| 'could-not-compile-project'
@@ -65,7 +65,7 @@ export class Messenger {
6565

6666
public sendErrorMessage(errorMessage: string, tabID: string) {
6767
this.dispatcher.sendErrorMessage(
68-
new ErrorMessage(`Sorry, we encountered a problem when processing your request.`, errorMessage, tabID)
68+
new ErrorMessage(CodeWhispererConstants.genericErrorMessage, errorMessage, tabID)
6969
)
7070
}
7171

@@ -195,7 +195,7 @@ export class Messenger {
195195
}
196196

197197
public sendCompilationInProgress(tabID: string) {
198-
const message = `I'm building your project. This can take up to 10 minutes, depending on the size of your project.`
198+
const message = CodeWhispererConstants.buildStartedChatMessage
199199

200200
this.dispatcher.sendAsyncEventProgress(
201201
new AsyncEventProgressMessage(tabID, { inProgress: true, message: undefined })
@@ -210,7 +210,7 @@ export class Messenger {
210210
}
211211

212212
public sendCompilationFinished(tabID: string) {
213-
const message = `I was able to build your project. I'll start transforming your code soon.`
213+
const message = CodeWhispererConstants.buildSucceededChatMessage
214214

215215
this.dispatcher.sendAsyncEventProgress(
216216
new AsyncEventProgressMessage(tabID, {
@@ -221,23 +221,22 @@ export class Messenger {
221221
}
222222

223223
public sendJobSubmittedMessage(tabID: string, disableJobActions: boolean = false) {
224-
const message = `I'm starting to transform your code. It can take 10 to 30 minutes to upgrade your code, depending on the size of your project. To monitor progress, go to the Transformation Hub.`
224+
const message = CodeWhispererConstants.jobStartedChatMessage
225225

226226
const buttons: ChatItemButton[] = []
227227

228228
if (!disableJobActions) {
229229
// Note: buttons can only be clicked once.
230-
// To get around this, we remove the card after they're clicked and then
231-
// resubmit the message.
230+
// To get around this, we remove the card after it's clicked and then resubmit the message.
232231
buttons.push({
233232
keepCardAfterClick: true,
234-
text: 'Open Transformation Hub',
233+
text: CodeWhispererConstants.openTransformationHubButtonText,
235234
id: ButtonActions.VIEW_TRANSFORMATION_HUB,
236235
})
237236

238237
buttons.push({
239238
keepCardAfterClick: true,
240-
text: 'Stop transformation',
239+
text: CodeWhispererConstants.stopTransformationButtonText,
241240
id: ButtonActions.STOP_TRANSFORMATION_JOB,
242241
})
243242
}
@@ -291,40 +290,29 @@ export class Messenger {
291290
let message = '...'
292291

293292
switch (type) {
294-
case 'no-workspace-open':
295-
message = 'To begin, please open a workspace.'
296-
break
297293
case 'no-project-found':
298-
message = `Sorry, I couldn't find any open projects. Currently, I can only upgrade Java projects built on Maven.
299-
300-
For more information, see the [Amazon Q documentation](https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html).`
294+
message = CodeWhispererConstants.noOpenProjectsFoundChatMessage
301295
break
302296
case 'no-java-project-found':
303-
message = `Sorry, I can't upgrade any of your open projects. Currently, I can only upgrade Java projects built on Maven.
304-
305-
For more information, see the [Amazon Q documentation](https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html).`
297+
message = CodeWhispererConstants.noJavaProjectsFoundChatMessage
306298
break
307299
case 'no-maven-java-project-found':
308-
message = `Sorry, I can't upgrade any of your open projects. I couldn't find a pom.xml file in any of your Java projects. Currently, I can only upgrade Java projects built on Maven.
309-
310-
For more information, see the [Amazon Q documentation](https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html).`
300+
message = CodeWhispererConstants.noPomXmlFoundChatMessage
311301
break
312302
case 'could-not-compile-project':
313-
message = `Sorry, I couldn't run Maven clean install to build your project. To troubleshoot, see the [Amazon Q documentation](https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#maven-commands-failing).`
303+
message = CodeWhispererConstants.cleanInstallErrorChatMessage
314304
break
315305
case 'invalid-java-home':
316-
message = `Sorry, I couldn't locate your Java installation. To troubleshoot, see the [Amazon Q documentation](https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#maven-commands-failing).`
306+
message = CodeWhispererConstants.noJavaHomeFoundChatMessage
317307
break
318308
case 'unsupported-source-jdk-version':
319-
message = `Sorry, currently I can only upgrade Java 8 or Java 11 projects.
320-
321-
For more information, see the [Amazon Q documentation.](https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html).`
309+
message = CodeWhispererConstants.unsupportedJavaVersionChatMessage
322310
}
323311

324312
const buttons: ChatItemButton[] = []
325313
buttons.push({
326314
keepCardAfterClick: false,
327-
text: 'Start a new transformation',
315+
text: CodeWhispererConstants.startTransformationButtonText,
328316
id: ButtonActions.CONFIRM_START_TRANSFORMATION_FLOW,
329317
})
330318

@@ -344,19 +332,11 @@ For more information, see the [Amazon Q documentation.](https://docs.aws.amazon.
344332
this.dispatcher.sendCommandMessage(new SendCommandMessage(message.command, message.tabId, message.eventId))
345333
}
346334

347-
public sendJobFinishedMessage(tabID: string, cancelled: boolean, jobStatus: string = '') {
348-
let message =
349-
'I cancelled your transformation. If you want to start another transformation, choose **Start a new transformation**.'
350-
351-
if (!cancelled) {
352-
message =
353-
'The transformation job is over. If you want to start another transformation, choose **Start a new transformation**.'
354-
}
355-
335+
public sendJobFinishedMessage(tabID: string, message: string = '') {
356336
const buttons: ChatItemButton[] = []
357337
buttons.push({
358338
keepCardAfterClick: false,
359-
text: 'Start a new transformation',
339+
text: CodeWhispererConstants.startTransformationButtonText,
360340
id: ButtonActions.CONFIRM_START_TRANSFORMATION_FLOW,
361341
})
362342

@@ -380,7 +360,7 @@ For more information, see the [Amazon Q documentation.](https://docs.aws.amazon.
380360
this.dispatcher.sendAsyncEventProgress(
381361
new AsyncEventProgressMessage(tabID, {
382362
inProgress: true,
383-
message: "I'm checking for open projects that are eligible for Code Transformation.",
363+
message: CodeWhispererConstants.checkingForProjectsChatMessage,
384364
})
385365
)
386366
}

packages/core/src/amazonqGumby/chat/controller/messenger/messengerUtils.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66

77
import * as os from 'os'
88
import { transformByQState, JDKVersion } from '../../../../codewhisperer/models/model'
9-
import {
10-
enterJavaHomeMessage,
11-
nonWindowsJava11HomeHelpMessage,
12-
nonWindowsJava8HomeHelpMessage,
13-
windowsJavaHomeHelpMessage,
14-
} from './stringConstants'
9+
import * as CodeWhispererConstants from '../../../../codewhisperer/models/constants'
1510

1611
// These enums map to string IDs
1712
export enum ButtonActions {
@@ -32,18 +27,20 @@ export enum GumbyCommands {
3227

3328
export default class MessengerUtils {
3429
static createJavaHomePrompt = (): string => {
35-
let javaHomePrompt = `${enterJavaHomeMessage} ${transformByQState.getSourceJDKVersion()}. \n`
30+
let javaHomePrompt = `${
31+
CodeWhispererConstants.enterJavaHomeChatMessage
32+
} ${transformByQState.getSourceJDKVersion()}. \n`
3633
if (os.platform() === 'win32') {
37-
javaHomePrompt += windowsJavaHomeHelpMessage.replace(
34+
javaHomePrompt += CodeWhispererConstants.windowsJavaHomeHelpChatMessage.replace(
3835
'JAVA_VERSION_HERE',
3936
transformByQState.getSourceJDKVersion()!
4037
)
4138
} else {
4239
const jdkVersion = transformByQState.getSourceJDKVersion()
4340
if (jdkVersion === JDKVersion.JDK8) {
44-
javaHomePrompt += ` ${nonWindowsJava8HomeHelpMessage}`
41+
javaHomePrompt += ` ${CodeWhispererConstants.nonWindowsJava8HomeHelpChatMessage}`
4542
} else if (jdkVersion === JDKVersion.JDK11) {
46-
javaHomePrompt += ` ${nonWindowsJava11HomeHelpMessage}`
43+
javaHomePrompt += ` ${CodeWhispererConstants.nonWindowsJava11HomeHelpChatMessage}`
4744
}
4845
}
4946
return javaHomePrompt
@@ -77,6 +74,6 @@ export default class MessengerUtils {
7774
}
7875
}
7976

80-
return `I can upgrade your ${javaVersionString}. To start the transformation, I need some information from you. Choose the project you want to upgrade and the target code version to upgrade to. Then, choose Transform.`
77+
return CodeWhispererConstants.projectPromptChatMessage.replace('JAVA_VERSION_HERE', javaVersionString)
8178
}
8279
}

packages/core/src/amazonqGumby/chat/controller/messenger/stringConstants.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)