@@ -241,7 +241,7 @@ export class TestController {
241
241
// eslint-disable-next-line unicorn/no-null
242
242
this . messenger . sendUpdatePromptProgress ( data . tabID , null )
243
243
const session = this . sessionStorage . getSession ( )
244
- const isCancel = data . error . message === unitTestGenerationCancelMessage
244
+ const isCancel = data . error . customerFacingMessage === unitTestGenerationCancelMessage
245
245
telemetry . amazonq_utgGenerateTests . emit ( {
246
246
cwsprChatProgrammingLanguage : session . fileLanguage ?? 'plaintext' ,
247
247
jobId : session . listOfTestGenerationJobId [ 0 ] , // For RIV, UTG does only one StartTestGeneration API call
@@ -257,56 +257,60 @@ export class TestController {
257
257
reasonDesc : getTelemetryReasonDesc ( data . error ) ,
258
258
isSupportedLanguage : true ,
259
259
credentialStartUrl : AuthUtil . instance . startUrl ,
260
+ httpStatusCode : data . error . statusCode ?? 0 , // If status code is 0, need to investigate where this is originating from.
260
261
} )
261
262
if ( session . stopIteration ) {
262
263
// Error from Science
263
- this . messenger . sendMessage ( data . error . message . replaceAll ( '```' , '' ) , data . tabID , 'answer' )
264
+ this . messenger . sendMessage ( data . error . customerFacingMessage . replaceAll ( '```' , '' ) , data . tabID , 'answer' )
264
265
} else {
265
266
isCancel
266
- ? this . messenger . sendMessage ( data . error . message , data . tabID , 'answer' )
267
+ ? this . messenger . sendMessage ( data . error . customerFacingMessage , data . tabID , 'answer' )
267
268
: this . sendErrorMessage ( data )
268
269
}
269
270
await this . sessionCleanUp ( )
270
271
return
271
272
}
272
273
// Client side error messages
273
- private sendErrorMessage ( data : { tabID : string ; error : { code : string ; message : string } } ) {
274
+ private sendErrorMessage ( data : {
275
+ tabID : string
276
+ error : { customerFacingMessage : string ; message : string ; code : string ; statusCode : string }
277
+ } ) {
274
278
const { error, tabID } = data
275
279
280
+ // If user reached montly limit for builderId
281
+ if ( error . code === 'CreateTestJobError' ) {
282
+ if ( error . message . includes ( CodeWhispererConstants . utgLimitReached ) ) {
283
+ getLogger ( ) . error ( 'Monthly quota reached for QSDA actions.' )
284
+ return this . messenger . sendMessage (
285
+ i18n ( 'AWS.amazonq.featureDev.error.monthlyLimitReached' ) ,
286
+ tabID ,
287
+ 'answer'
288
+ )
289
+ } else {
290
+ getLogger ( ) . error ( 'Too many requests.' )
291
+ // TODO: move to constants file
292
+ return this . messenger . sendErrorMessage ( 'Too many requests. Please wait before retrying.' , tabID )
293
+ }
294
+ }
276
295
if ( isAwsError ( error ) ) {
277
296
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
- }
297
+ // TODO: use the explicitly modeled exception reason for quota vs throttle{
298
+ getLogger ( ) . error ( 'Too many requests.' )
299
+ // TODO: move to constants file
300
+ this . messenger . sendErrorMessage ( 'Too many requests. Please wait before retrying.' , tabID )
291
301
} else {
292
302
// other service errors:
293
303
// AccessDeniedException - should not happen because access is validated before this point in the client
294
304
// ValidationException - shouldn't happen because client should not send malformed requests
295
305
// ConflictException - should not happen because the client will maintain proper state
296
306
// InternalServerException - shouldn't happen but needs to be caught
297
307
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
- )
308
+ this . messenger . sendErrorMessage ( '' , tabID )
302
309
}
303
310
} else {
304
311
// other unexpected errors (TODO enumerate all other failure cases)
305
- 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
- )
312
+ getLogger ( ) . error ( 'Other error message: %s' , error . customerFacingMessage )
313
+ this . messenger . sendErrorMessage ( '' , tabID )
310
314
}
311
315
}
312
316
@@ -716,6 +720,14 @@ export class TestController {
716
720
// TODO: send the message once again once build is enabled
717
721
//this.messenger.sendMessage('Accepted', message.tabID, 'prompt')
718
722
telemetry . ui_click . emit ( { elementId : 'unitTestGeneration_acceptDiff' } )
723
+ getLogger ( ) . info (
724
+ session . fileLanguage ?? 'plaintext' ,
725
+ session . listOfTestGenerationJobId [ 0 ] ,
726
+ session . testGenerationJobGroupName ,
727
+ 'Succeeded' ,
728
+ AuthUtil . instance . startUrl ,
729
+ '200'
730
+ )
719
731
telemetry . amazonq_utgGenerateTests . emit ( {
720
732
generatedCount : session . numberOfTestsGenerated ,
721
733
acceptedCount : session . numberOfTestsGenerated ,
@@ -736,10 +748,10 @@ export class TestController {
736
748
isSupportedLanguage : true ,
737
749
credentialStartUrl : AuthUtil . instance . startUrl ,
738
750
result : 'Succeeded' ,
751
+ httpStatusCode : '200' ,
739
752
} )
740
753
741
754
await this . endSession ( message , FollowUpTypes . SkipBuildAndFinish )
742
- await this . sessionCleanUp ( )
743
755
return
744
756
745
757
if ( session . listOfTestGenerationJobId . length === 1 ) {
@@ -860,6 +872,7 @@ export class TestController {
860
872
isSupportedLanguage : true ,
861
873
credentialStartUrl : AuthUtil . instance . startUrl ,
862
874
result : 'Succeeded' ,
875
+ httpStatusCode : '200' ,
863
876
} )
864
877
telemetry . ui_click . emit ( { elementId : 'unitTestGeneration_rejectDiff' } )
865
878
}
@@ -1304,8 +1317,17 @@ export class TestController {
1304
1317
'Deleting output.log and temp result directory. testGenerationLogsDir: %s' ,
1305
1318
testGenerationLogsDir
1306
1319
)
1307
- await fs . delete ( path . join ( testGenerationLogsDir , 'output.log' ) )
1308
- await fs . delete ( this . tempResultDirPath , { recursive : true } )
1320
+ if ( await fs . existsFile ( path . join ( testGenerationLogsDir , 'output.log' ) ) ) {
1321
+ await fs . delete ( path . join ( testGenerationLogsDir , 'output.log' ) )
1322
+ }
1323
+ if (
1324
+ await fs
1325
+ . stat ( this . tempResultDirPath )
1326
+ . then ( ( ) => true )
1327
+ . catch ( ( ) => false )
1328
+ ) {
1329
+ await fs . delete ( this . tempResultDirPath , { recursive : true } )
1330
+ }
1309
1331
}
1310
1332
1311
1333
// TODO: return build command when product approves
0 commit comments