Skip to content

Commit 86f87a5

Browse files
authored
fix(amazonq): /test: show descriptive error message (aws#6795)
## Problem Currently, when test generation fails, users see a generic error message: `Sorry, I am experiencing technical issues at the moment. Please try again in a few minutes.` This message doesn't provide actionable information to help users resolve the issue. ## Solution Enhanced error handling to display specific error messages from the backend. For example, when a test generation command is malformed, users will now see a descriptive message like: `I apologize, but I couldn't process your /test instruction. Try: /test and optionally specify a class, function or method.` These targeted error messages help users understand and correct their inputs. --- <img width="1722" alt="Screenshot 2025-03-17 at 10 01 53 AM" src="https://github.com/user-attachments/assets/0f2c3279-de93-4e20-9263-cdf1eebf4603" /> - 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 33b526a commit 86f87a5

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
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": "/test: show descriptive error message"
4+
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import { ChatSessionManager } from '../../amazonqTest/chat/storages/chatSession'
2020
import { ChildProcess, spawn } from 'child_process' // eslint-disable-line no-restricted-imports
2121
import { BuildStatus } from '../../amazonqTest/chat/session/session'
2222
import { fs } from '../../shared/fs/fs'
23-
import { TestGenerationJobStatus } from '../models/constants'
24-
import { TestGenFailedError } from '../../amazonqTest/error'
2523
import { Range } from '../client/codewhispereruserclient'
2624

2725
// eslint-disable-next-line unicorn/no-null
@@ -112,18 +110,13 @@ export async function startTestGenerationProcess(
112110
if (!shouldContinueRunning(tabID)) {
113111
return
114112
}
115-
const jobStatus = await pollTestJobStatus(
113+
await pollTestJobStatus(
116114
testJob.testGenerationJob.testGenerationJobId,
117115
testJob.testGenerationJob.testGenerationJobGroupName,
118116
filePath,
119117
initialExecution
120118
)
121119
// TODO: Send status to test summary
122-
if (jobStatus === TestGenerationJobStatus.FAILED) {
123-
session.numberOfTestsGenerated = 0
124-
logger.verbose(`Test generation failed.`)
125-
throw new TestGenFailedError()
126-
}
127120
throwIfCancelled()
128121
if (!shouldContinueRunning(tabID)) {
129122
return

packages/core/src/codewhisperer/service/testGenHandler.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
CreateUploadUrlError,
1919
ExportResultsArchiveError,
2020
InvalidSourceZipError,
21+
TestGenFailedError,
2122
TestGenStoppedError,
2223
TestGenTimedOutError,
2324
} from '../../amazonqTest/error'
@@ -193,9 +194,17 @@ export async function pollTestJobStatus(
193194
}
194195
}
195196
ChatSessionManager.Instance.getSession().targetFileInfo = targetFileInfo
196-
if (resp.testGenerationJob?.status !== CodeWhispererConstants.TestGenerationJobStatus.IN_PROGRESS) {
197-
// This can be FAILED or COMPLETED
198-
status = resp.testGenerationJob?.status as CodeWhispererConstants.TestGenerationJobStatus
197+
status = resp.testGenerationJob?.status as CodeWhispererConstants.TestGenerationJobStatus
198+
if (status === CodeWhispererConstants.TestGenerationJobStatus.FAILED) {
199+
session.numberOfTestsGenerated = 0
200+
logger.verbose(`Test generation failed.`)
201+
if (resp.testGenerationJob?.jobStatusReason) {
202+
session.stopIteration = true
203+
throw new TestGenFailedError(resp.testGenerationJob?.jobStatusReason)
204+
} else {
205+
throw new TestGenFailedError()
206+
}
207+
} else if (status === CodeWhispererConstants.TestGenerationJobStatus.COMPLETED) {
199208
logger.verbose(`testgen job status: ${status}`)
200209
logger.verbose(`Complete polling test job status.`)
201210
break

0 commit comments

Comments
 (0)