@@ -20,6 +20,7 @@ import {
2020 TelemetryHelper ,
2121 TestGenerationBuildStep ,
2222 testGenState ,
23+ tooManyRequestErrorMessage ,
2324 unitTestGenerationCancelMessage ,
2425 UserWrittenCodeTracker ,
2526} from '../../../codewhisperer'
@@ -242,72 +243,76 @@ export class TestController {
242243 // eslint-disable-next-line unicorn/no-null
243244 this . messenger . sendUpdatePromptProgress ( data . tabID , null )
244245 const session = this . sessionStorage . getSession ( )
245- const isCancel = data . error . message === unitTestGenerationCancelMessage
246-
246+ const isCancel = data . error . uiMessage === unitTestGenerationCancelMessage
247+ let telemetryErrorMessage = getTelemetryReasonDesc ( data . error )
248+ if ( session . stopIteration ) {
249+ telemetryErrorMessage = getTelemetryReasonDesc ( data . error . uiMessage . replaceAll ( '```' , '' ) )
250+ }
247251 TelemetryHelper . instance . sendTestGenerationToolkitEvent (
248252 session ,
249253 true ,
250254 true ,
251255 isCancel ? 'Cancelled' : 'Failed' ,
252256 session . startTestGenerationRequestId ,
253257 performance . now ( ) - session . testGenerationStartTime ,
254- getTelemetryReasonDesc ( data . error ) ,
258+ telemetryErrorMessage ,
255259 session . isCodeBlockSelected ,
256260 session . artifactsUploadDuration ,
257261 session . srcPayloadSize ,
258262 session . srcZipFileSize
259263 )
260-
261264 if ( session . stopIteration ) {
262265 // Error from Science
263- this . messenger . sendMessage ( data . error . message . replaceAll ( '```' , '' ) , data . tabID , 'answer' )
266+ this . messenger . sendMessage ( data . error . uiMessage . replaceAll ( '```' , '' ) , data . tabID , 'answer' )
264267 } else {
265268 isCancel
266- ? this . messenger . sendMessage ( data . error . message , data . tabID , 'answer' )
269+ ? this . messenger . sendMessage ( data . error . uiMessage , data . tabID , 'answer' )
267270 : this . sendErrorMessage ( data )
268271 }
269272 await this . sessionCleanUp ( )
270273 return
271274 }
272275 // Client side error messages
273- private sendErrorMessage ( data : { tabID : string ; error : { code : string ; message : string } } ) {
276+ private sendErrorMessage ( data : {
277+ tabID : string
278+ error : { uiMessage : string ; message : string ; code : string ; statusCode : string }
279+ } ) {
274280 const { error, tabID } = data
275281
282+ // If user reached monthly limit for builderId
283+ if ( error . code === 'CreateTestJobError' ) {
284+ if ( error . message . includes ( CodeWhispererConstants . utgLimitReached ) ) {
285+ getLogger ( ) . error ( 'Monthly quota reached for QSDA actions.' )
286+ return this . messenger . sendMessage (
287+ i18n ( 'AWS.amazonq.featureDev.error.monthlyLimitReached' ) ,
288+ tabID ,
289+ 'answer'
290+ )
291+ }
292+ if ( error . message . includes ( 'Too many requests' ) ) {
293+ getLogger ( ) . error ( error . message )
294+ return this . messenger . sendErrorMessage ( tooManyRequestErrorMessage , tabID )
295+ }
296+ }
276297 if ( isAwsError ( error ) ) {
277298 if ( error . code === 'ThrottlingException' ) {
278- // TODO: use the explicitly modeled exception reason for quota vs throttle
279- if ( error . message . includes ( CodeWhispererConstants . utgLimitReached ) ) {
280- getLogger ( ) . error ( 'Monthly quota reached for QSDA actions.' )
281- return this . messenger . sendMessage (
282- i18n ( 'AWS.amazonq.featureDev.error.monthlyLimitReached' ) ,
283- tabID ,
284- 'answer'
285- )
286- } else {
287- getLogger ( ) . error ( 'Too many requests.' )
288- // TODO: move to constants file
289- this . messenger . sendErrorMessage ( 'Too many requests. Please wait before retrying.' , tabID )
290- }
291- } else {
292- // other service errors:
293- // AccessDeniedException - should not happen because access is validated before this point in the client
294- // ValidationException - shouldn't happen because client should not send malformed requests
295- // ConflictException - should not happen because the client will maintain proper state
296- // InternalServerException - shouldn't happen but needs to be caught
297- getLogger ( ) . error ( 'Other error message: %s' , error . message )
298- this . messenger . sendErrorMessage (
299- 'Encountered an unexpected error when generating tests. Please try again' ,
300- tabID
301- )
299+ // TODO: use the explicitly modeled exception reason for quota vs throttle{
300+ getLogger ( ) . error ( error . message )
301+ this . messenger . sendErrorMessage ( tooManyRequestErrorMessage , tabID )
302+ return
302303 }
303- } else {
304- // other unexpected errors (TODO enumerate all other failure cases)
304+ // other service errors:
305+ // AccessDeniedException - should not happen because access is validated before this point in the client
306+ // ValidationException - shouldn't happen because client should not send malformed requests
307+ // ConflictException - should not happen because the client will maintain proper state
308+ // InternalServerException - shouldn't happen but needs to be caught
305309 getLogger ( ) . error ( 'Other error message: %s' , error . message )
306- this . messenger . sendErrorMessage (
307- 'Encountered an unexpected error when generating tests. Please try again' ,
308- tabID
309- )
310+ this . messenger . sendErrorMessage ( '' , tabID )
311+ return
310312 }
313+ // other unexpected errors (TODO enumerate all other failure cases)
314+ getLogger ( ) . error ( 'Other error message: %s' , error . uiMessage )
315+ this . messenger . sendErrorMessage ( '' , tabID )
311316 }
312317
313318 // This function handles actions if user clicked on any Button one of these cases will be executed
@@ -730,6 +735,9 @@ export class TestController {
730735 // this.messenger.sendMessage('Accepted', message.tabID, 'prompt')
731736 telemetry . ui_click . emit ( { elementId : 'unitTestGeneration_acceptDiff' } )
732737
738+ getLogger ( ) . info (
739+ `Generated unit tests are accepted for ${ session . fileLanguage ?? 'plaintext' } language with jobId: ${ session . listOfTestGenerationJobId [ 0 ] } , jobGroupName: ${ session . testGenerationJobGroupName } , result: Succeeded`
740+ )
733741 TelemetryHelper . instance . sendTestGenerationToolkitEvent (
734742 session ,
735743 true ,
@@ -751,7 +759,6 @@ export class TestController {
751759 )
752760
753761 await this . endSession ( message , FollowUpTypes . SkipBuildAndFinish )
754- await this . sessionCleanUp ( )
755762 return
756763
757764 if ( session . listOfTestGenerationJobId . length === 1 ) {
@@ -876,16 +883,12 @@ export class TestController {
876883 session . numberOfTestsGenerated ,
877884 session . linesOfCodeGenerated
878885 )
879-
880886 telemetry . ui_click . emit ( { elementId : 'unitTestGeneration_rejectDiff' } )
881887 }
882888
883889 await this . sessionCleanUp ( )
884- // TODO: revert 'Accepted' to 'Skip build and finish' once supported
885- const message = step === FollowUpTypes . RejectCode ? 'Rejected' : 'Accepted'
886890
887- this . messenger . sendMessage ( message , data . tabID , 'prompt' )
888- this . messenger . sendMessage ( `Unit test generation workflow is completed.` , data . tabID , 'answer' )
891+ // this.messenger.sendMessage(`Unit test generation workflow is completed.`, data.tabID, 'answer')
889892 this . messenger . sendChatInputEnabled ( data . tabID , true )
890893 return
891894 }
@@ -1320,8 +1323,18 @@ export class TestController {
13201323 'Deleting output.log and temp result directory. testGenerationLogsDir: %s' ,
13211324 testGenerationLogsDir
13221325 )
1323- await fs . delete ( path . join ( testGenerationLogsDir , 'output.log' ) )
1324- await fs . delete ( this . tempResultDirPath , { recursive : true } )
1326+ const outputLogPath = path . join ( testGenerationLogsDir , 'output.log' )
1327+ if ( await fs . existsFile ( outputLogPath ) ) {
1328+ await fs . delete ( outputLogPath )
1329+ }
1330+ if (
1331+ await fs
1332+ . stat ( this . tempResultDirPath )
1333+ . then ( ( ) => true )
1334+ . catch ( ( ) => false )
1335+ ) {
1336+ await fs . delete ( this . tempResultDirPath , { recursive : true } )
1337+ }
13251338 }
13261339
13271340 // TODO: return build command when product approves
0 commit comments