Skip to content

Commit 34dc101

Browse files
dhasani23David Hasani
and
David Hasani
authored
fix(amazonq): log full error (#6422)
## Problem When API calls fail, it can be difficult to debug without the requestId. ## Solution Log entire error to ensure we have all relevant details, not just the error message. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: David Hasani <[email protected]>
1 parent 02d21a2 commit 34dc101

File tree

1 file changed

+24
-40
lines changed

1 file changed

+24
-40
lines changed

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

+24-40
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ 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)) {
133135
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
169171
}
170172
} catch (e: any) {
171173
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)
173175
throw new Error(errorMessage)
174176
}
175177
}
@@ -180,18 +182,12 @@ export async function stopJob(jobId: string) {
180182
}
181183

182184
try {
183-
const response = await codeWhisperer.codeWhispererClient.codeModernizerStopCodeTransformation({
185+
await codeWhisperer.codeWhispererClient.codeModernizerStopCodeTransformation({
184186
transformationJobId: jobId,
185187
})
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-
}
192188
} 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)
195191
throw new Error('Stop job failed')
196192
}
197193
}
@@ -209,12 +205,10 @@ export async function uploadPayload(payloadFileName: string, uploadContext?: Upl
209205
uploadIntent: CodeWhispererConstants.uploadIntent,
210206
uploadContext,
211207
})
212-
if (response.$response.requestId) {
213-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
214-
}
215208
} 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)
218212
throw new Error(errorMessage)
219213
}
220214

@@ -449,13 +443,11 @@ export async function startJob(uploadId: string) {
449443
},
450444
})
451445
getLogger().info('CodeTransformation: called startJob API successfully')
452-
if (response.$response.requestId) {
453-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
454-
}
455446
return response.transformationJobId
456447
} catch (e: any) {
457448
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)
459451
throw new Error(errorMessage)
460452
}
461453
}
@@ -573,9 +565,6 @@ export async function getTransformationPlan(jobId: string) {
573565
response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({
574566
transformationJobId: jobId,
575567
})
576-
if (response.$response.requestId) {
577-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
578-
}
579568

580569
const stepZeroProgressUpdates = response.transformationPlan.transformationSteps[0].progressUpdates
581570

@@ -618,13 +607,14 @@ export async function getTransformationPlan(jobId: string) {
618607
return plan
619608
} catch (e: any) {
620609
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)
622612

623613
/* Means API call failed
624614
* If response is defined, means a display/parsing error occurred, so continue transformation
625615
*/
626616
if (response === undefined) {
627-
throw new Error('Get plan API call failed')
617+
throw new Error(errorMessage)
628618
}
629619
}
630620
}
@@ -638,13 +628,10 @@ export async function getTransformationSteps(jobId: string, handleThrottleFlag:
638628
const response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({
639629
transformationJobId: jobId,
640630
})
641-
if (response.$response.requestId) {
642-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
643-
}
644631
return response.transformationPlan.transformationSteps.slice(1) // skip step 0 (contains supplemental info)
645632
} 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)
648635
throw e
649636
}
650637
}
@@ -682,7 +669,6 @@ export async function pollTransformationJob(jobId: string, validStates: string[]
682669
transformByQState.setJobFailureErrorNotification(
683670
`${CodeWhispererConstants.failedToCompleteJobGenericNotification} ${errorMessage}`
684671
)
685-
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
686672
}
687673
if (validStates.includes(status)) {
688674
break
@@ -700,14 +686,14 @@ export async function pollTransformationJob(jobId: string, validStates: string[]
700686
* is called, we break above on validStatesForCheckingDownloadUrl and check final status in finalizeTransformationJob
701687
*/
702688
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+
)
705692
}
706693
await sleep(CodeWhispererConstants.transformationJobPollingIntervalSeconds * 1000)
707694
} 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'})`)
711697
throw e
712698
}
713699
}
@@ -752,7 +738,6 @@ export async function downloadResultArchive(
752738
pathToArchive: string,
753739
downloadArtifactType: TransformationDownloadArtifactType
754740
) {
755-
let downloadErrorMessage = undefined
756741
const cwStreamingClient = await createCodeWhispererChatStreamingClient()
757742

758743
try {
@@ -765,8 +750,7 @@ export async function downloadResultArchive(
765750
pathToArchive
766751
)
767752
} catch (e: any) {
768-
downloadErrorMessage = (e as Error).message
769-
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
753+
getLogger().error(`CodeTransformation: ExportResultArchive error = %O`, e)
770754
throw e
771755
} finally {
772756
cwStreamingClient.destroy()
@@ -795,7 +779,7 @@ export async function downloadAndExtractResultArchive(
795779
zip.extractAllTo(pathToArchiveDir)
796780
} catch (e) {
797781
downloadErrorMessage = (e as Error).message
798-
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
782+
getLogger().error(`CodeTransformation: ExportResultArchive error = %O`, e)
799783
throw new Error('Error downloading transformation result artifacts: ' + downloadErrorMessage)
800784
}
801785
}

0 commit comments

Comments
 (0)