Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amazonq): log full error #6422

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,14 @@
if (response.status === 200) {
break
}
throw new Error('Upload failed')
throw new Error(
`Upload failed, status = ${response.status}; full response: ${JSON.stringify(response)}`
)
} catch (e: any) {
if (response && !retriableCodes.includes(response.status)) {
throw new Error(`Upload failed with status code = ${response.status}; did not automatically retry`)
throw new Error(
`Upload failed with status code = ${response.status}; did not automatically retry; full error = ${JSON.stringify(e)}`
)
}
if (i !== 3) {
await sleep(1000 * Math.pow(2, i))
Expand Down Expand Up @@ -169,7 +173,7 @@
}
} catch (e: any) {
const errorMessage = `Resuming the job failed due to: ${(e as Error).message}`
getLogger().error(`CodeTransformation: ResumeTransformation error = ${errorMessage}`)
getLogger().error(`CodeTransformation: ResumeTransformation error = ${JSON.stringify(e)}`)

Check failure on line 176 in packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Avoid using JSON.stringify within logging and error messages, prefer %O in general or inspect from collectionUtils for custom depth formatting
throw new Error(errorMessage)
}
}
Expand All @@ -180,18 +184,12 @@
}

try {
const response = await codeWhisperer.codeWhispererClient.codeModernizerStopCodeTransformation({
await codeWhisperer.codeWhispererClient.codeModernizerStopCodeTransformation({
transformationJobId: jobId,
})
if (response !== undefined) {
// always store request ID, but it will only show up in a notification if an error occurs
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}
}
} catch (e: any) {
const errorMessage = (e as Error).message
getLogger().error(`CodeTransformation: StopTransformation error = ${errorMessage}`)
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
getLogger().error(`CodeTransformation: StopTransformation error = ${JSON.stringify(e)}`)

Check failure on line 192 in packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Avoid using JSON.stringify within logging and error messages, prefer %O in general or inspect from collectionUtils for custom depth formatting
throw new Error('Stop job failed')
}
}
Expand All @@ -209,12 +207,10 @@
uploadIntent: CodeWhispererConstants.uploadIntent,
uploadContext,
})
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}
} catch (e: any) {
const errorMessage = `The upload failed due to: ${(e as Error).message}`
getLogger().error(`CodeTransformation: CreateUploadUrl error: = ${e}`)
const errorMessage = `Creating the upload URL failed due to: ${(e as Error).message}`
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
getLogger().error(`CodeTransformation: CreateUploadUrl error: = ${JSON.stringify(e)}`)

Check failure on line 213 in packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Avoid using JSON.stringify within logging and error messages, prefer %O in general or inspect from collectionUtils for custom depth formatting
throw new Error(errorMessage)
}

Expand Down Expand Up @@ -449,13 +445,11 @@
},
})
getLogger().info('CodeTransformation: called startJob API successfully')
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}
return response.transformationJobId
} catch (e: any) {
const errorMessage = `Starting the job failed due to: ${(e as Error).message}`
getLogger().error(`CodeTransformation: StartTransformation error = ${errorMessage}`)
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
getLogger().error(`CodeTransformation: StartTransformation error = ${JSON.stringify(e)}`)

Check failure on line 452 in packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Avoid using JSON.stringify within logging and error messages, prefer %O in general or inspect from collectionUtils for custom depth formatting
throw new Error(errorMessage)
}
}
Expand Down Expand Up @@ -573,9 +567,6 @@
response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({
transformationJobId: jobId,
})
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}

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

Expand Down Expand Up @@ -618,13 +609,14 @@
return plan
} catch (e: any) {
const errorMessage = (e as Error).message
getLogger().error(`CodeTransformation: GetTransformationPlan error = ${errorMessage}`)
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
getLogger().error(`CodeTransformation: GetTransformationPlan error = ${JSON.stringify(e)}`)

Check failure on line 613 in packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Avoid using JSON.stringify within logging and error messages, prefer %O in general or inspect from collectionUtils for custom depth formatting

/* Means API call failed
* If response is defined, means a display/parsing error occurred, so continue transformation
*/
if (response === undefined) {
throw new Error('Get plan API call failed')
throw new Error(errorMessage)
}
}
}
Expand All @@ -638,13 +630,10 @@
const response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({
transformationJobId: jobId,
})
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}
return response.transformationPlan.transformationSteps.slice(1) // skip step 0 (contains supplemental info)
} catch (e: any) {
const errorMessage = (e as Error).message
getLogger().error(`CodeTransformation: GetTransformationPlan error = ${errorMessage}`)
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
getLogger().error(`CodeTransformation: GetTransformationPlan error = ${JSON.stringify(e)}`)

Check failure on line 636 in packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Avoid using JSON.stringify within logging and error messages, prefer %O in general or inspect from collectionUtils for custom depth formatting
throw e
}
}
Expand Down Expand Up @@ -682,7 +671,6 @@
transformByQState.setJobFailureErrorNotification(
`${CodeWhispererConstants.failedToCompleteJobGenericNotification} ${errorMessage}`
)
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}
if (validStates.includes(status)) {
break
Expand All @@ -700,14 +688,14 @@
* is called, we break above on validStatesForCheckingDownloadUrl and check final status in finalizeTransformationJob
*/
if (CodeWhispererConstants.failureStates.includes(status)) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
throw new JobStoppedError(response.$response.requestId)
throw new JobStoppedError(
response.transformationJob.reason ?? 'no failure reason in GetTransformation response'
)
}
await sleep(CodeWhispererConstants.transformationJobPollingIntervalSeconds * 1000)
} catch (e: any) {
let errorMessage = (e as Error).message
errorMessage += ` -- ${transformByQState.getJobFailureMetadata()}`
getLogger().error(`CodeTransformation: GetTransformation error = ${errorMessage}`)
getLogger().error(`CodeTransformation: GetTransformation error = ${JSON.stringify(e)}`)

Check failure on line 697 in packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Avoid using JSON.stringify within logging and error messages, prefer %O in general or inspect from collectionUtils for custom depth formatting
transformByQState.setJobFailureMetadata(` (request ID: ${e.requestId ?? 'unavailable'})`)
throw e
}
}
Expand Down Expand Up @@ -752,7 +740,6 @@
pathToArchive: string,
downloadArtifactType: TransformationDownloadArtifactType
) {
let downloadErrorMessage = undefined
const cwStreamingClient = await createCodeWhispererChatStreamingClient()

try {
Expand All @@ -765,8 +752,7 @@
pathToArchive
)
} catch (e: any) {
downloadErrorMessage = (e as Error).message
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
getLogger().error(`CodeTransformation: ExportResultArchive error = ${JSON.stringify(e)}`)

Check failure on line 755 in packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Avoid using JSON.stringify within logging and error messages, prefer %O in general or inspect from collectionUtils for custom depth formatting
throw e
} finally {
cwStreamingClient.destroy()
Expand Down Expand Up @@ -795,7 +781,7 @@
zip.extractAllTo(pathToArchiveDir)
} catch (e) {
downloadErrorMessage = (e as Error).message
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
getLogger().error(`CodeTransformation: ExportResultArchive error = ${JSON.stringify(e)}`)

Check failure on line 784 in packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

Avoid using JSON.stringify within logging and error messages, prefer %O in general or inspect from collectionUtils for custom depth formatting
throw new Error('Error downloading transformation result artifacts: ' + downloadErrorMessage)
}
}
Expand Down
Loading