55
66import * as vscode from 'vscode'
77import * as fs from 'fs' // eslint-disable-line no-restricted-imports
8+ import os from 'os'
89import path from 'path'
910import { getLogger } from '../../shared/logger/logger'
1011import * as CodeWhispererConstants from '../models/constants'
@@ -16,7 +17,6 @@ import {
1617 jobPlanProgress ,
1718 FolderInfo ,
1819 ZipManifest ,
19- TransformByQStatus ,
2020 TransformationType ,
2121 TransformationCandidateProject ,
2222 RegionProfile ,
@@ -44,7 +44,6 @@ import {
4444 validateOpenProjects ,
4545} from '../service/transformByQ/transformProjectValidationHandler'
4646import {
47- getVersionData ,
4847 prepareProjectDependencies ,
4948 runMavenDependencyUpdateCommands ,
5049} from '../service/transformByQ/transformMavenHandler'
@@ -83,7 +82,7 @@ import { AuthUtil } from '../util/authUtil'
8382
8483export function getFeedbackCommentData ( ) {
8584 const jobId = transformByQState . getJobId ( )
86- const s = `Q CodeTransform jobId: ${ jobId ? jobId : 'none' } `
85+ const s = `Q CodeTransformation jobId: ${ jobId ? jobId : 'none' } `
8786 return s
8887}
8988
@@ -113,8 +112,8 @@ export async function compileProject() {
113112 try {
114113 const dependenciesFolder : FolderInfo = getDependenciesFolderInfo ( )
115114 transformByQState . setDependencyFolderInfo ( dependenciesFolder )
116- const modulePath = transformByQState . getProjectPath ( )
117- await prepareProjectDependencies ( dependenciesFolder , modulePath )
115+ const projectPath = transformByQState . getProjectPath ( )
116+ await prepareProjectDependencies ( dependenciesFolder . path , projectPath )
118117 } catch ( err ) {
119118 // open build-logs.txt file to show user error logs
120119 await writeAndShowBuildLogs ( true )
@@ -176,18 +175,15 @@ export async function humanInTheLoopRetryLogic(jobId: string, profile: RegionPro
176175 if ( status === 'PAUSED' ) {
177176 const hilStatusFailure = await initiateHumanInTheLoopPrompt ( jobId )
178177 if ( hilStatusFailure ) {
179- // We rejected the changes and resumed the job and should
180- // try to resume normal polling asynchronously
178+ // resume polling
181179 void humanInTheLoopRetryLogic ( jobId , profile )
182180 }
183181 } else {
184182 await finalizeTransformByQ ( status )
185183 }
186184 } catch ( error ) {
187185 status = 'FAILED'
188- // TODO if we encounter error in HIL, do we stop job?
189186 await finalizeTransformByQ ( status )
190- // bubble up error to callee function
191187 throw error
192188 }
193189}
@@ -226,11 +222,9 @@ export async function preTransformationUploadCode() {
226222
227223 const payloadFilePath = zipCodeResult . tempFilePath
228224 const zipSize = zipCodeResult . fileSize
229- const dependenciesCopied = zipCodeResult . dependenciesCopied
230225
231226 telemetry . record ( {
232227 codeTransformTotalByteSize : zipSize ,
233- codeTransformDependenciesCopied : dependenciesCopied ,
234228 } )
235229
236230 transformByQState . setPayloadFilePath ( payloadFilePath )
@@ -409,7 +403,7 @@ export async function finishHumanInTheLoop(selectedDependency?: string) {
409403
410404 // 7) We need to take that output of maven and use CreateUploadUrl
411405 const uploadFolderInfo = humanInTheLoopManager . getUploadFolderInfo ( )
412- await prepareProjectDependencies ( uploadFolderInfo , uploadFolderInfo . path )
406+ await prepareProjectDependencies ( uploadFolderInfo . path , uploadFolderInfo . path )
413407 // zipCode side effects deletes the uploadFolderInfo right away
414408 const uploadResult = await zipCode ( {
415409 dependenciesFolder : uploadFolderInfo ,
@@ -450,13 +444,11 @@ export async function finishHumanInTheLoop(selectedDependency?: string) {
450444 await terminateHILEarly ( jobId )
451445 void humanInTheLoopRetryLogic ( jobId , profile )
452446 } finally {
453- // Always delete the dependency directories
454447 telemetry . codeTransform_humanInTheLoop . emit ( {
455448 codeTransformSessionId : CodeTransformTelemetryState . instance . getSessionId ( ) ,
456449 codeTransformJobId : jobId ,
457450 codeTransformMetadata : CodeTransformTelemetryState . instance . getCodeTransformMetaDataString ( ) ,
458451 result : hilResult ,
459- // TODO: make a generic reason field for telemetry logging so we don't log sensitive PII data
460452 reason : hilResult === MetadataResult . Fail ? 'Runtime error occurred' : undefined ,
461453 } )
462454 await HumanInTheLoopManager . instance . cleanUpArtifacts ( )
@@ -505,7 +497,7 @@ export async function startTransformationJob(
505497 throw new JobStartError ( )
506498 }
507499
508- await sleep ( 2000 ) // sleep before polling job to prevent ThrottlingException
500+ await sleep ( 5000 ) // sleep before polling job status to prevent ThrottlingException
509501 throwIfCancelled ( )
510502
511503 return jobId
@@ -524,9 +516,7 @@ export async function pollTransformationStatusUntilPlanReady(jobId: string, prof
524516 transformByQState . setJobFailureErrorChatMessage ( CodeWhispererConstants . failedToCompleteJobChatMessage )
525517 }
526518
527- // Since we don't yet have a good way of knowing what the error was,
528- // we try to fetch any build failure artifacts that may exist so that we can optionally
529- // show them to the user if they exist.
519+ // try to download pre-build error logs if available
530520 let pathToLog = ''
531521 try {
532522 const tempToolkitFolder = await makeTemporaryToolkitFolder ( )
@@ -713,23 +703,16 @@ export async function postTransformationJob() {
713703 const durationInMs = calculateTotalLatency ( CodeTransformTelemetryState . instance . getStartTime ( ) )
714704 const resultStatusMessage = transformByQState . getStatus ( )
715705
716- if ( transformByQState . getTransformationType ( ) !== TransformationType . SQL_CONVERSION ) {
717- // the below is only applicable when user is doing a Java 8/11 language upgrade
718- const versionInfo = await getVersionData ( )
719- const mavenVersionInfoMessage = `${ versionInfo [ 0 ] } (${ transformByQState . getMavenName ( ) } )`
720- const javaVersionInfoMessage = `${ versionInfo [ 1 ] } (${ transformByQState . getMavenName ( ) } )`
721-
722- telemetry . codeTransform_totalRunTime . emit ( {
723- buildSystemVersion : mavenVersionInfoMessage ,
724- codeTransformSessionId : CodeTransformTelemetryState . instance . getSessionId ( ) ,
725- codeTransformJobId : transformByQState . getJobId ( ) ,
726- codeTransformResultStatusMessage : resultStatusMessage ,
727- codeTransformRunTimeLatency : durationInMs ,
728- codeTransformLocalJavaVersion : javaVersionInfoMessage ,
729- result : resultStatusMessage === TransformByQStatus . Succeeded ? MetadataResult . Pass : MetadataResult . Fail ,
730- reason : `${ resultStatusMessage } -${ chatMessage } ` ,
731- } )
732- }
706+ telemetry . codeTransform_totalRunTime . emit ( {
707+ codeTransformSessionId : CodeTransformTelemetryState . instance . getSessionId ( ) ,
708+ codeTransformJobId : transformByQState . getJobId ( ) ,
709+ codeTransformResultStatusMessage : resultStatusMessage ,
710+ codeTransformRunTimeLatency : durationInMs ,
711+ result :
712+ transformByQState . isSucceeded ( ) || transformByQState . isPartiallySucceeded ( )
713+ ? MetadataResult . Pass
714+ : MetadataResult . Fail ,
715+ } )
733716
734717 if ( transformByQState . isSucceeded ( ) ) {
735718 void vscode . window . showInformationMessage ( CodeWhispererConstants . jobCompletedNotification ( diffMessage ) , {
@@ -752,9 +735,14 @@ export async function postTransformationJob() {
752735 } )
753736 }
754737
755- if ( transformByQState . getPayloadFilePath ( ) !== '' ) {
738+ if ( transformByQState . getPayloadFilePath ( ) ) {
756739 // delete original upload ZIP at very end of transformation
757- fs . rmSync ( transformByQState . getPayloadFilePath ( ) , { recursive : true , force : true } )
740+ fs . rmSync ( transformByQState . getPayloadFilePath ( ) , { force : true } )
741+ }
742+ // delete temporary build logs file
743+ const logFilePath = path . join ( os . tmpdir ( ) , 'build-logs.txt' )
744+ if ( fs . existsSync ( logFilePath ) ) {
745+ fs . rmSync ( logFilePath , { force : true } )
758746 }
759747
760748 // attempt download for user
@@ -772,12 +760,9 @@ export async function transformationJobErrorHandler(error: any) {
772760 // jobFailureErrorNotification should always be defined here
773761 let displayedErrorMessage =
774762 transformByQState . getJobFailureErrorNotification ( ) ?? CodeWhispererConstants . failedToCompleteJobNotification
775- if ( transformByQState . getJobFailureMetadata ( ) !== '' ) {
776- displayedErrorMessage += ` ${ transformByQState . getJobFailureMetadata ( ) } `
777- transformByQState . setJobFailureErrorChatMessage (
778- `${ transformByQState . getJobFailureErrorChatMessage ( ) } ${ transformByQState . getJobFailureMetadata ( ) } `
779- )
780- }
763+ transformByQState . setJobFailureErrorChatMessage (
764+ transformByQState . getJobFailureErrorChatMessage ( ) ?? CodeWhispererConstants . failedToCompleteJobChatMessage
765+ )
781766 void vscode . window
782767 . showErrorMessage ( displayedErrorMessage , CodeWhispererConstants . amazonQFeedbackText )
783768 . then ( ( choice ) => {
0 commit comments