Skip to content

Commit 682ff10

Browse files
author
David Hasani
committed
fix(amazonq): log full error
1 parent f004173 commit 682ff10

File tree

1 file changed

+27
-41
lines changed

1 file changed

+27
-41
lines changed

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,14 @@ export async function uploadArtifactToS3(
127127
if (response.status === 200) {
128128
break
129129
}
130-
throw new Error('Upload failed')
130+
throw new Error(
131+
`Upload failed, status = ${response.status}; full response: ${JSON.stringify(response)}`
132+
)
131133
} catch (e: any) {
132134
if (response && !retriableCodes.includes(response.status)) {
133-
throw new Error(`Upload failed with status code = ${response.status}; did not automatically retry`)
135+
throw new Error(
136+
`Upload failed with status code = ${response.status}; did not automatically retry; full error = ${JSON.stringify(e)}`
137+
)
134138
}
135139
if (i !== 3) {
136140
await sleep(1000 * Math.pow(2, i))
@@ -169,7 +173,7 @@ export async function resumeTransformationJob(jobId: string, userActionStatus: T
169173
}
170174
} catch (e: any) {
171175
const errorMessage = `Resuming the job failed due to: ${(e as Error).message}`
172-
getLogger().error(`CodeTransformation: ResumeTransformation error = ${errorMessage}`)
176+
getLogger().error(`CodeTransformation: ResumeTransformation error = ${JSON.stringify(e)}`)
173177
throw new Error(errorMessage)
174178
}
175179
}
@@ -180,18 +184,12 @@ export async function stopJob(jobId: string) {
180184
}
181185

182186
try {
183-
const response = await codeWhisperer.codeWhispererClient.codeModernizerStopCodeTransformation({
187+
await codeWhisperer.codeWhispererClient.codeModernizerStopCodeTransformation({
184188
transformationJobId: jobId,
185189
})
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-
}
192190
} catch (e: any) {
193-
const errorMessage = (e as Error).message
194-
getLogger().error(`CodeTransformation: StopTransformation error = ${errorMessage}`)
191+
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
192+
getLogger().error(`CodeTransformation: StopTransformation error = ${JSON.stringify(e)}`)
195193
throw new Error('Stop job failed')
196194
}
197195
}
@@ -209,12 +207,10 @@ export async function uploadPayload(payloadFileName: string, uploadContext?: Upl
209207
uploadIntent: CodeWhispererConstants.uploadIntent,
210208
uploadContext,
211209
})
212-
if (response.$response.requestId) {
213-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
214-
}
215210
} catch (e: any) {
216-
const errorMessage = `The upload failed due to: ${(e as Error).message}`
217-
getLogger().error(`CodeTransformation: CreateUploadUrl error: = ${e}`)
211+
const errorMessage = `Creating the upload URL failed due to: ${(e as Error).message}`
212+
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
213+
getLogger().error(`CodeTransformation: CreateUploadUrl error: = ${JSON.stringify(e)}`)
218214
throw new Error(errorMessage)
219215
}
220216

@@ -449,13 +445,11 @@ export async function startJob(uploadId: string) {
449445
},
450446
})
451447
getLogger().info('CodeTransformation: called startJob API successfully')
452-
if (response.$response.requestId) {
453-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
454-
}
455448
return response.transformationJobId
456449
} catch (e: any) {
457450
const errorMessage = `Starting the job failed due to: ${(e as Error).message}`
458-
getLogger().error(`CodeTransformation: StartTransformation error = ${errorMessage}`)
451+
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
452+
getLogger().error(`CodeTransformation: StartTransformation error = ${JSON.stringify(e)}`)
459453
throw new Error(errorMessage)
460454
}
461455
}
@@ -573,9 +567,6 @@ export async function getTransformationPlan(jobId: string) {
573567
response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({
574568
transformationJobId: jobId,
575569
})
576-
if (response.$response.requestId) {
577-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
578-
}
579570

580571
const stepZeroProgressUpdates = response.transformationPlan.transformationSteps[0].progressUpdates
581572

@@ -618,13 +609,14 @@ export async function getTransformationPlan(jobId: string) {
618609
return plan
619610
} catch (e: any) {
620611
const errorMessage = (e as Error).message
621-
getLogger().error(`CodeTransformation: GetTransformationPlan error = ${errorMessage}`)
612+
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
613+
getLogger().error(`CodeTransformation: GetTransformationPlan error = ${JSON.stringify(e)}`)
622614

623615
/* Means API call failed
624616
* If response is defined, means a display/parsing error occurred, so continue transformation
625617
*/
626618
if (response === undefined) {
627-
throw new Error('Get plan API call failed')
619+
throw new Error(errorMessage)
628620
}
629621
}
630622
}
@@ -638,13 +630,10 @@ export async function getTransformationSteps(jobId: string, handleThrottleFlag:
638630
const response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({
639631
transformationJobId: jobId,
640632
})
641-
if (response.$response.requestId) {
642-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
643-
}
644633
return response.transformationPlan.transformationSteps.slice(1) // skip step 0 (contains supplemental info)
645634
} catch (e: any) {
646-
const errorMessage = (e as Error).message
647-
getLogger().error(`CodeTransformation: GetTransformationPlan error = ${errorMessage}`)
635+
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
636+
getLogger().error(`CodeTransformation: GetTransformationPlan error = ${JSON.stringify(e)}`)
648637
throw e
649638
}
650639
}
@@ -682,7 +671,6 @@ export async function pollTransformationJob(jobId: string, validStates: string[]
682671
transformByQState.setJobFailureErrorNotification(
683672
`${CodeWhispererConstants.failedToCompleteJobGenericNotification} ${errorMessage}`
684673
)
685-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
686674
}
687675
if (validStates.includes(status)) {
688676
break
@@ -700,14 +688,14 @@ export async function pollTransformationJob(jobId: string, validStates: string[]
700688
* is called, we break above on validStatesForCheckingDownloadUrl and check final status in finalizeTransformationJob
701689
*/
702690
if (CodeWhispererConstants.failureStates.includes(status)) {
703-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
704-
throw new JobStoppedError(response.$response.requestId)
691+
throw new JobStoppedError(
692+
response.transformationJob.reason ?? 'no failure reason in GetTransformation response'
693+
)
705694
}
706695
await sleep(CodeWhispererConstants.transformationJobPollingIntervalSeconds * 1000)
707696
} catch (e: any) {
708-
let errorMessage = (e as Error).message
709-
errorMessage += ` -- ${transformByQState.getJobFailureMetadata()}`
710-
getLogger().error(`CodeTransformation: GetTransformation error = ${errorMessage}`)
697+
getLogger().error(`CodeTransformation: GetTransformation error = ${JSON.stringify(e)}`)
698+
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
711699
throw e
712700
}
713701
}
@@ -752,7 +740,6 @@ export async function downloadResultArchive(
752740
pathToArchive: string,
753741
downloadArtifactType: TransformationDownloadArtifactType
754742
) {
755-
let downloadErrorMessage = undefined
756743
const cwStreamingClient = await createCodeWhispererChatStreamingClient()
757744

758745
try {
@@ -765,8 +752,7 @@ export async function downloadResultArchive(
765752
pathToArchive
766753
)
767754
} catch (e: any) {
768-
downloadErrorMessage = (e as Error).message
769-
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
755+
getLogger().error(`CodeTransformation: ExportResultArchive error = ${JSON.stringify(e)}`)
770756
throw e
771757
} finally {
772758
cwStreamingClient.destroy()
@@ -795,7 +781,7 @@ export async function downloadAndExtractResultArchive(
795781
zip.extractAllTo(pathToArchiveDir)
796782
} catch (e) {
797783
downloadErrorMessage = (e as Error).message
798-
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
784+
getLogger().error(`CodeTransformation: ExportResultArchive error = ${JSON.stringify(e)}`)
799785
throw new Error('Error downloading transformation result artifacts: ' + downloadErrorMessage)
800786
}
801787
}

0 commit comments

Comments
 (0)