diff --git a/packages/amazonq/.changes/next-release/Bug Fix-7bb4ae68-204d-48a1-a510-490d2a2a938a.json b/packages/amazonq/.changes/next-release/Bug Fix-7bb4ae68-204d-48a1-a510-490d2a2a938a.json new file mode 100644 index 00000000000..b7f9ab81cc7 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-7bb4ae68-204d-48a1-a510-490d2a2a938a.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "/test: show descriptive error message" +} diff --git a/packages/core/src/codewhisperer/commands/startTestGeneration.ts b/packages/core/src/codewhisperer/commands/startTestGeneration.ts index abc8c8ec74c..29e7148a17b 100644 --- a/packages/core/src/codewhisperer/commands/startTestGeneration.ts +++ b/packages/core/src/codewhisperer/commands/startTestGeneration.ts @@ -20,8 +20,6 @@ import { ChatSessionManager } from '../../amazonqTest/chat/storages/chatSession' import { ChildProcess, spawn } from 'child_process' // eslint-disable-line no-restricted-imports import { BuildStatus } from '../../amazonqTest/chat/session/session' import { fs } from '../../shared/fs/fs' -import { TestGenerationJobStatus } from '../models/constants' -import { TestGenFailedError } from '../../amazonqTest/error' import { Range } from '../client/codewhispereruserclient' // eslint-disable-next-line unicorn/no-null @@ -112,18 +110,13 @@ export async function startTestGenerationProcess( if (!shouldContinueRunning(tabID)) { return } - const jobStatus = await pollTestJobStatus( + await pollTestJobStatus( testJob.testGenerationJob.testGenerationJobId, testJob.testGenerationJob.testGenerationJobGroupName, filePath, initialExecution ) // TODO: Send status to test summary - if (jobStatus === TestGenerationJobStatus.FAILED) { - session.numberOfTestsGenerated = 0 - logger.verbose(`Test generation failed.`) - throw new TestGenFailedError() - } throwIfCancelled() if (!shouldContinueRunning(tabID)) { return diff --git a/packages/core/src/codewhisperer/service/testGenHandler.ts b/packages/core/src/codewhisperer/service/testGenHandler.ts index bd3f2167d83..3f4825d37ca 100644 --- a/packages/core/src/codewhisperer/service/testGenHandler.ts +++ b/packages/core/src/codewhisperer/service/testGenHandler.ts @@ -18,6 +18,7 @@ import { CreateUploadUrlError, ExportResultsArchiveError, InvalidSourceZipError, + TestGenFailedError, TestGenStoppedError, TestGenTimedOutError, } from '../../amazonqTest/error' @@ -193,9 +194,17 @@ export async function pollTestJobStatus( } } ChatSessionManager.Instance.getSession().targetFileInfo = targetFileInfo - if (resp.testGenerationJob?.status !== CodeWhispererConstants.TestGenerationJobStatus.IN_PROGRESS) { - // This can be FAILED or COMPLETED - status = resp.testGenerationJob?.status as CodeWhispererConstants.TestGenerationJobStatus + status = resp.testGenerationJob?.status as CodeWhispererConstants.TestGenerationJobStatus + if (status === CodeWhispererConstants.TestGenerationJobStatus.FAILED) { + session.numberOfTestsGenerated = 0 + logger.verbose(`Test generation failed.`) + if (resp.testGenerationJob?.jobStatusReason) { + session.stopIteration = true + throw new TestGenFailedError(resp.testGenerationJob?.jobStatusReason) + } else { + throw new TestGenFailedError() + } + } else if (status === CodeWhispererConstants.TestGenerationJobStatus.COMPLETED) { logger.verbose(`testgen job status: ${status}`) logger.verbose(`Complete polling test job status.`) break