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 ,
@@ -43,7 +43,6 @@ import {
4343 validateOpenProjects ,
4444} from '../service/transformByQ/transformProjectValidationHandler'
4545import {
46- getVersionData ,
4746 prepareProjectDependencies ,
4847 runMavenDependencyUpdateCommands ,
4948} from '../service/transformByQ/transformMavenHandler'
@@ -82,7 +81,7 @@ import { AuthUtil } from '../util/authUtil'
8281
8382export function getFeedbackCommentData ( ) {
8483 const jobId = transformByQState . getJobId ( )
85- const s = `Q CodeTransform jobId: ${ jobId ? jobId : 'none' } `
84+ const s = `Q CodeTransformation jobId: ${ jobId ? jobId : 'none' } `
8685 return s
8786}
8887
@@ -112,8 +111,8 @@ export async function compileProject() {
112111 try {
113112 const dependenciesFolder : FolderInfo = getDependenciesFolderInfo ( )
114113 transformByQState . setDependencyFolderInfo ( dependenciesFolder )
115- const modulePath = transformByQState . getProjectPath ( )
116- await prepareProjectDependencies ( dependenciesFolder , modulePath )
114+ const projectPath = transformByQState . getProjectPath ( )
115+ await prepareProjectDependencies ( dependenciesFolder . path , projectPath )
117116 } catch ( err ) {
118117 // open build-logs.txt file to show user error logs
119118 await writeAndShowBuildLogs ( true )
@@ -175,18 +174,15 @@ export async function humanInTheLoopRetryLogic(jobId: string, profile: RegionPro
175174 if ( status === 'PAUSED' ) {
176175 const hilStatusFailure = await initiateHumanInTheLoopPrompt ( jobId )
177176 if ( hilStatusFailure ) {
178- // We rejected the changes and resumed the job and should
179- // try to resume normal polling asynchronously
177+ // resume polling
180178 void humanInTheLoopRetryLogic ( jobId , profile )
181179 }
182180 } else {
183181 await finalizeTransformByQ ( status )
184182 }
185183 } catch ( error ) {
186184 status = 'FAILED'
187- // TODO if we encounter error in HIL, do we stop job?
188185 await finalizeTransformByQ ( status )
189- // bubble up error to callee function
190186 throw error
191187 }
192188}
@@ -225,11 +221,9 @@ export async function preTransformationUploadCode() {
225221
226222 const payloadFilePath = zipCodeResult . tempFilePath
227223 const zipSize = zipCodeResult . fileSize
228- const dependenciesCopied = zipCodeResult . dependenciesCopied
229224
230225 telemetry . record ( {
231226 codeTransformTotalByteSize : zipSize ,
232- codeTransformDependenciesCopied : dependenciesCopied ,
233227 } )
234228
235229 transformByQState . setPayloadFilePath ( payloadFilePath )
@@ -408,7 +402,7 @@ export async function finishHumanInTheLoop(selectedDependency?: string) {
408402
409403 // 7) We need to take that output of maven and use CreateUploadUrl
410404 const uploadFolderInfo = humanInTheLoopManager . getUploadFolderInfo ( )
411- await prepareProjectDependencies ( uploadFolderInfo , uploadFolderInfo . path )
405+ await prepareProjectDependencies ( uploadFolderInfo . path , uploadFolderInfo . path )
412406 // zipCode side effects deletes the uploadFolderInfo right away
413407 const uploadResult = await zipCode ( {
414408 dependenciesFolder : uploadFolderInfo ,
@@ -449,13 +443,11 @@ export async function finishHumanInTheLoop(selectedDependency?: string) {
449443 await terminateHILEarly ( jobId )
450444 void humanInTheLoopRetryLogic ( jobId , profile )
451445 } finally {
452- // Always delete the dependency directories
453446 telemetry . codeTransform_humanInTheLoop . emit ( {
454447 codeTransformSessionId : CodeTransformTelemetryState . instance . getSessionId ( ) ,
455448 codeTransformJobId : jobId ,
456449 codeTransformMetadata : CodeTransformTelemetryState . instance . getCodeTransformMetaDataString ( ) ,
457450 result : hilResult ,
458- // TODO: make a generic reason field for telemetry logging so we don't log sensitive PII data
459451 reason : hilResult === MetadataResult . Fail ? 'Runtime error occurred' : undefined ,
460452 } )
461453 await HumanInTheLoopManager . instance . cleanUpArtifacts ( )
@@ -504,7 +496,7 @@ export async function startTransformationJob(
504496 throw new JobStartError ( )
505497 }
506498
507- await sleep ( 2000 ) // sleep before polling job to prevent ThrottlingException
499+ await sleep ( 5000 ) // sleep before polling job status to prevent ThrottlingException
508500 throwIfCancelled ( )
509501
510502 return jobId
@@ -523,9 +515,7 @@ export async function pollTransformationStatusUntilPlanReady(jobId: string, prof
523515 transformByQState . setJobFailureErrorChatMessage ( CodeWhispererConstants . failedToCompleteJobChatMessage )
524516 }
525517
526- // Since we don't yet have a good way of knowing what the error was,
527- // we try to fetch any build failure artifacts that may exist so that we can optionally
528- // show them to the user if they exist.
518+ // try to download pre-build error logs if available
529519 let pathToLog = ''
530520 try {
531521 const tempToolkitFolder = await makeTemporaryToolkitFolder ( )
@@ -689,23 +679,16 @@ export async function postTransformationJob() {
689679 const durationInMs = calculateTotalLatency ( CodeTransformTelemetryState . instance . getStartTime ( ) )
690680 const resultStatusMessage = transformByQState . getStatus ( )
691681
692- if ( transformByQState . getTransformationType ( ) !== TransformationType . SQL_CONVERSION ) {
693- // the below is only applicable when user is doing a Java 8/11 language upgrade
694- const versionInfo = await getVersionData ( )
695- const mavenVersionInfoMessage = `${ versionInfo [ 0 ] } (${ transformByQState . getMavenName ( ) } )`
696- const javaVersionInfoMessage = `${ versionInfo [ 1 ] } (${ transformByQState . getMavenName ( ) } )`
697-
698- telemetry . codeTransform_totalRunTime . emit ( {
699- buildSystemVersion : mavenVersionInfoMessage ,
700- codeTransformSessionId : CodeTransformTelemetryState . instance . getSessionId ( ) ,
701- codeTransformJobId : transformByQState . getJobId ( ) ,
702- codeTransformResultStatusMessage : resultStatusMessage ,
703- codeTransformRunTimeLatency : durationInMs ,
704- codeTransformLocalJavaVersion : javaVersionInfoMessage ,
705- result : resultStatusMessage === TransformByQStatus . Succeeded ? MetadataResult . Pass : MetadataResult . Fail ,
706- reason : `${ resultStatusMessage } -${ chatMessage } ` ,
707- } )
708- }
682+ telemetry . codeTransform_totalRunTime . emit ( {
683+ codeTransformSessionId : CodeTransformTelemetryState . instance . getSessionId ( ) ,
684+ codeTransformJobId : transformByQState . getJobId ( ) ,
685+ codeTransformResultStatusMessage : resultStatusMessage ,
686+ codeTransformRunTimeLatency : durationInMs ,
687+ result :
688+ transformByQState . isSucceeded ( ) || transformByQState . isPartiallySucceeded ( )
689+ ? MetadataResult . Pass
690+ : MetadataResult . Fail ,
691+ } )
709692
710693 if ( transformByQState . isSucceeded ( ) ) {
711694 void vscode . window . showInformationMessage ( CodeWhispererConstants . jobCompletedNotification , {
@@ -728,9 +711,14 @@ export async function postTransformationJob() {
728711 } )
729712 }
730713
731- if ( transformByQState . getPayloadFilePath ( ) !== '' ) {
714+ if ( transformByQState . getPayloadFilePath ( ) ) {
732715 // delete original upload ZIP at very end of transformation
733- fs . rmSync ( transformByQState . getPayloadFilePath ( ) , { recursive : true , force : true } )
716+ fs . rmSync ( transformByQState . getPayloadFilePath ( ) , { force : true } )
717+ }
718+ // delete temporary build logs file
719+ const logFilePath = path . join ( os . tmpdir ( ) , 'build-logs.txt' )
720+ if ( fs . existsSync ( logFilePath ) ) {
721+ fs . rmSync ( logFilePath , { force : true } )
734722 }
735723
736724 // attempt download for user
@@ -748,12 +736,9 @@ export async function transformationJobErrorHandler(error: any) {
748736 // jobFailureErrorNotification should always be defined here
749737 let displayedErrorMessage =
750738 transformByQState . getJobFailureErrorNotification ( ) ?? CodeWhispererConstants . failedToCompleteJobNotification
751- if ( transformByQState . getJobFailureMetadata ( ) !== '' ) {
752- displayedErrorMessage += ` ${ transformByQState . getJobFailureMetadata ( ) } `
753- transformByQState . setJobFailureErrorChatMessage (
754- `${ transformByQState . getJobFailureErrorChatMessage ( ) } ${ transformByQState . getJobFailureMetadata ( ) } `
755- )
756- }
739+ transformByQState . setJobFailureErrorChatMessage (
740+ transformByQState . getJobFailureErrorChatMessage ( ) ?? CodeWhispererConstants . failedToCompleteJobChatMessage
741+ )
757742 void vscode . window
758743 . showErrorMessage ( displayedErrorMessage , CodeWhispererConstants . amazonQFeedbackText )
759744 . then ( ( choice ) => {
0 commit comments