@@ -127,7 +127,9 @@ export async function uploadArtifactToS3(
127
127
if ( response . status === 200 ) {
128
128
break
129
129
}
130
- throw new Error ( 'Upload failed' )
130
+ throw new Error (
131
+ `Upload failed, status = ${ response . status } ; full response: ${ JSON . stringify ( response ) } `
132
+ )
131
133
} catch ( e : any ) {
132
134
if ( response && ! retriableCodes . includes ( response . status ) ) {
133
135
throw new Error ( `Upload failed with status code = ${ response . status } ; did not automatically retry` )
@@ -169,7 +171,7 @@ export async function resumeTransformationJob(jobId: string, userActionStatus: T
169
171
}
170
172
} catch ( e : any ) {
171
173
const errorMessage = `Resuming the job failed due to: ${ ( e as Error ) . message } `
172
- getLogger ( ) . error ( `CodeTransformation: ResumeTransformation error = ${ errorMessage } ` )
174
+ getLogger ( ) . error ( `CodeTransformation: ResumeTransformation error = %O` , e )
173
175
throw new Error ( errorMessage )
174
176
}
175
177
}
@@ -180,18 +182,12 @@ export async function stopJob(jobId: string) {
180
182
}
181
183
182
184
try {
183
- const response = await codeWhisperer . codeWhispererClient . codeModernizerStopCodeTransformation ( {
185
+ await codeWhisperer . codeWhispererClient . codeModernizerStopCodeTransformation ( {
184
186
transformationJobId : jobId ,
185
187
} )
186
- if ( response !== undefined ) {
187
- // always store request ID, but it will only show up in a notification if an error occurs
188
- if ( response . $response . requestId ) {
189
- transformByQState . setJobFailureMetadata ( ` (request ID: ${ response . $response . requestId } )` )
190
- }
191
- }
192
188
} catch ( e : any ) {
193
- const errorMessage = ( e as Error ) . message
194
- getLogger ( ) . error ( `CodeTransformation: StopTransformation error = ${ errorMessage } ` )
189
+ transformByQState . setJobFailureMetadata ( ` (request ID: ${ e . requestId ?? 'unavailable' } )` )
190
+ getLogger ( ) . error ( `CodeTransformation: StopTransformation error = %O` , e )
195
191
throw new Error ( 'Stop job failed' )
196
192
}
197
193
}
@@ -209,12 +205,10 @@ export async function uploadPayload(payloadFileName: string, uploadContext?: Upl
209
205
uploadIntent : CodeWhispererConstants . uploadIntent ,
210
206
uploadContext,
211
207
} )
212
- if ( response . $response . requestId ) {
213
- transformByQState . setJobFailureMetadata ( ` (request ID: ${ response . $response . requestId } )` )
214
- }
215
208
} catch ( e : any ) {
216
- const errorMessage = `The upload failed due to: ${ ( e as Error ) . message } `
217
- getLogger ( ) . error ( `CodeTransformation: CreateUploadUrl error: = ${ e } ` )
209
+ const errorMessage = `Creating the upload URL failed due to: ${ ( e as Error ) . message } `
210
+ transformByQState . setJobFailureMetadata ( ` (request ID: ${ e . requestId ?? 'unavailable' } )` )
211
+ getLogger ( ) . error ( `CodeTransformation: CreateUploadUrl error: = %O` , e )
218
212
throw new Error ( errorMessage )
219
213
}
220
214
@@ -449,13 +443,11 @@ export async function startJob(uploadId: string) {
449
443
} ,
450
444
} )
451
445
getLogger ( ) . info ( 'CodeTransformation: called startJob API successfully' )
452
- if ( response . $response . requestId ) {
453
- transformByQState . setJobFailureMetadata ( ` (request ID: ${ response . $response . requestId } )` )
454
- }
455
446
return response . transformationJobId
456
447
} catch ( e : any ) {
457
448
const errorMessage = `Starting the job failed due to: ${ ( e as Error ) . message } `
458
- getLogger ( ) . error ( `CodeTransformation: StartTransformation error = ${ errorMessage } ` )
449
+ transformByQState . setJobFailureMetadata ( ` (request ID: ${ e . requestId ?? 'unavailable' } )` )
450
+ getLogger ( ) . error ( `CodeTransformation: StartTransformation error = %O` , e )
459
451
throw new Error ( errorMessage )
460
452
}
461
453
}
@@ -573,9 +565,6 @@ export async function getTransformationPlan(jobId: string) {
573
565
response = await codeWhisperer . codeWhispererClient . codeModernizerGetCodeTransformationPlan ( {
574
566
transformationJobId : jobId ,
575
567
} )
576
- if ( response . $response . requestId ) {
577
- transformByQState . setJobFailureMetadata ( ` (request ID: ${ response . $response . requestId } )` )
578
- }
579
568
580
569
const stepZeroProgressUpdates = response . transformationPlan . transformationSteps [ 0 ] . progressUpdates
581
570
@@ -618,13 +607,14 @@ export async function getTransformationPlan(jobId: string) {
618
607
return plan
619
608
} catch ( e : any ) {
620
609
const errorMessage = ( e as Error ) . message
621
- getLogger ( ) . error ( `CodeTransformation: GetTransformationPlan error = ${ errorMessage } ` )
610
+ transformByQState . setJobFailureMetadata ( ` (request ID: ${ e . requestId ?? 'unavailable' } )` )
611
+ getLogger ( ) . error ( `CodeTransformation: GetTransformationPlan error = %O` , e )
622
612
623
613
/* Means API call failed
624
614
* If response is defined, means a display/parsing error occurred, so continue transformation
625
615
*/
626
616
if ( response === undefined ) {
627
- throw new Error ( 'Get plan API call failed' )
617
+ throw new Error ( errorMessage )
628
618
}
629
619
}
630
620
}
@@ -638,13 +628,10 @@ export async function getTransformationSteps(jobId: string, handleThrottleFlag:
638
628
const response = await codeWhisperer . codeWhispererClient . codeModernizerGetCodeTransformationPlan ( {
639
629
transformationJobId : jobId ,
640
630
} )
641
- if ( response . $response . requestId ) {
642
- transformByQState . setJobFailureMetadata ( ` (request ID: ${ response . $response . requestId } )` )
643
- }
644
631
return response . transformationPlan . transformationSteps . slice ( 1 ) // skip step 0 (contains supplemental info)
645
632
} catch ( e : any ) {
646
- const errorMessage = ( e as Error ) . message
647
- getLogger ( ) . error ( `CodeTransformation: GetTransformationPlan error = ${ errorMessage } ` )
633
+ transformByQState . setJobFailureMetadata ( ` (request ID: ${ e . requestId ?? 'unavailable' } )` )
634
+ getLogger ( ) . error ( `CodeTransformation: GetTransformationPlan error = %O` , e )
648
635
throw e
649
636
}
650
637
}
@@ -682,7 +669,6 @@ export async function pollTransformationJob(jobId: string, validStates: string[]
682
669
transformByQState . setJobFailureErrorNotification (
683
670
`${ CodeWhispererConstants . failedToCompleteJobGenericNotification } ${ errorMessage } `
684
671
)
685
- transformByQState . setJobFailureMetadata ( ` (request ID: ${ response . $response . requestId } )` )
686
672
}
687
673
if ( validStates . includes ( status ) ) {
688
674
break
@@ -700,14 +686,14 @@ export async function pollTransformationJob(jobId: string, validStates: string[]
700
686
* is called, we break above on validStatesForCheckingDownloadUrl and check final status in finalizeTransformationJob
701
687
*/
702
688
if ( CodeWhispererConstants . failureStates . includes ( status ) ) {
703
- transformByQState . setJobFailureMetadata ( ` (request ID: ${ response . $response . requestId } )` )
704
- throw new JobStoppedError ( response . $response . requestId )
689
+ throw new JobStoppedError (
690
+ response . transformationJob . reason ?? 'no failure reason in GetTransformation response'
691
+ )
705
692
}
706
693
await sleep ( CodeWhispererConstants . transformationJobPollingIntervalSeconds * 1000 )
707
694
} catch ( e : any ) {
708
- let errorMessage = ( e as Error ) . message
709
- errorMessage += ` -- ${ transformByQState . getJobFailureMetadata ( ) } `
710
- getLogger ( ) . error ( `CodeTransformation: GetTransformation error = ${ errorMessage } ` )
695
+ getLogger ( ) . error ( `CodeTransformation: GetTransformation error = %O` , e )
696
+ transformByQState . setJobFailureMetadata ( ` (request ID: ${ e . requestId ?? 'unavailable' } )` )
711
697
throw e
712
698
}
713
699
}
@@ -752,7 +738,6 @@ export async function downloadResultArchive(
752
738
pathToArchive : string ,
753
739
downloadArtifactType : TransformationDownloadArtifactType
754
740
) {
755
- let downloadErrorMessage = undefined
756
741
const cwStreamingClient = await createCodeWhispererChatStreamingClient ( )
757
742
758
743
try {
@@ -765,8 +750,7 @@ export async function downloadResultArchive(
765
750
pathToArchive
766
751
)
767
752
} catch ( e : any ) {
768
- downloadErrorMessage = ( e as Error ) . message
769
- getLogger ( ) . error ( `CodeTransformation: ExportResultArchive error = ${ downloadErrorMessage } ` )
753
+ getLogger ( ) . error ( `CodeTransformation: ExportResultArchive error = %O` , e )
770
754
throw e
771
755
} finally {
772
756
cwStreamingClient . destroy ( )
@@ -795,7 +779,7 @@ export async function downloadAndExtractResultArchive(
795
779
zip . extractAllTo ( pathToArchiveDir )
796
780
} catch ( e ) {
797
781
downloadErrorMessage = ( e as Error ) . message
798
- getLogger ( ) . error ( `CodeTransformation: ExportResultArchive error = ${ downloadErrorMessage } ` )
782
+ getLogger ( ) . error ( `CodeTransformation: ExportResultArchive error = %O` , e )
799
783
throw new Error ( 'Error downloading transformation result artifacts: ' + downloadErrorMessage )
800
784
}
801
785
}
0 commit comments