@@ -241,7 +241,7 @@ export class TestController {
241241 // eslint-disable-next-line unicorn/no-null
242242 this . messenger . sendUpdatePromptProgress ( data . tabID , null )
243243 const session = this . sessionStorage . getSession ( )
244- const isCancel = data . error . message === unitTestGenerationCancelMessage
244+ const isCancel = data . error . customerFacingMessage === unitTestGenerationCancelMessage
245245 telemetry . amazonq_utgGenerateTests . emit ( {
246246 cwsprChatProgrammingLanguage : session . fileLanguage ?? 'plaintext' ,
247247 jobId : session . listOfTestGenerationJobId [ 0 ] , // For RIV, UTG does only one StartTestGeneration API call
@@ -257,56 +257,60 @@ export class TestController {
257257 reasonDesc : getTelemetryReasonDesc ( data . error ) ,
258258 isSupportedLanguage : true ,
259259 credentialStartUrl : AuthUtil . instance . startUrl ,
260+ httpStatusCode : data . error . statusCode ?? 0 , // If status code is 0, need to investigate where this is originating from.
260261 } )
261262 if ( session . stopIteration ) {
262263 // 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' )
264265 } else {
265266 isCancel
266- ? this . messenger . sendMessage ( data . error . message , data . tabID , 'answer' )
267+ ? this . messenger . sendMessage ( data . error . customerFacingMessage , data . tabID , 'answer' )
267268 : this . sendErrorMessage ( data )
268269 }
269270 await this . sessionCleanUp ( )
270271 return
271272 }
272273 // 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+ } ) {
274278 const { error, tabID } = data
275279
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+ }
276295 if ( isAwsError ( error ) ) {
277296 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 )
291301 } else {
292302 // other service errors:
293303 // AccessDeniedException - should not happen because access is validated before this point in the client
294304 // ValidationException - shouldn't happen because client should not send malformed requests
295305 // ConflictException - should not happen because the client will maintain proper state
296306 // InternalServerException - shouldn't happen but needs to be caught
297307 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 )
302309 }
303310 } else {
304311 // 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 )
310314 }
311315 }
312316
@@ -716,6 +720,14 @@ export class TestController {
716720 // TODO: send the message once again once build is enabled
717721 //this.messenger.sendMessage('Accepted', message.tabID, 'prompt')
718722 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+ )
719731 telemetry . amazonq_utgGenerateTests . emit ( {
720732 generatedCount : session . numberOfTestsGenerated ,
721733 acceptedCount : session . numberOfTestsGenerated ,
@@ -736,10 +748,10 @@ export class TestController {
736748 isSupportedLanguage : true ,
737749 credentialStartUrl : AuthUtil . instance . startUrl ,
738750 result : 'Succeeded' ,
751+ httpStatusCode : '200' ,
739752 } )
740753
741754 await this . endSession ( message , FollowUpTypes . SkipBuildAndFinish )
742- await this . sessionCleanUp ( )
743755 return
744756
745757 if ( session . listOfTestGenerationJobId . length === 1 ) {
@@ -860,6 +872,7 @@ export class TestController {
860872 isSupportedLanguage : true ,
861873 credentialStartUrl : AuthUtil . instance . startUrl ,
862874 result : 'Succeeded' ,
875+ httpStatusCode : '200' ,
863876 } )
864877 telemetry . ui_click . emit ( { elementId : 'unitTestGeneration_rejectDiff' } )
865878 }
@@ -1304,8 +1317,17 @@ export class TestController {
13041317 'Deleting output.log and temp result directory. testGenerationLogsDir: %s' ,
13051318 testGenerationLogsDir
13061319 )
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+ }
13091331 }
13101332
13111333 // TODO: return build command when product approves
0 commit comments