Skip to content

Commit 2af9a40

Browse files
dhasani23David Hasani
and
David Hasani
authored
fix(amazonq): show exact error message when job fails (#4494)
* fix(amazonq): show exact error message when job fails * fix detekt issues --------- Co-authored-by: David Hasani <davhasan@amazon.com>
1 parent 5b29f05 commit 2af9a40

File tree

8 files changed

+27
-16
lines changed

8 files changed

+27
-16
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Amazon Q Code Transformation: show exact error messages in chat when job fails"
4+
}

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import java.nio.file.Path
3939
import java.time.Instant
4040
import java.util.concurrent.atomic.AtomicBoolean
4141

42-
data class DownloadArtifactResult(val artifact: CodeModernizerArtifact?, val zipPath: String)
42+
data class DownloadArtifactResult(val artifact: CodeModernizerArtifact?, val zipPath: String, val errorMessage: String = "")
4343

4444
class ArtifactHandler(private val project: Project, private val clientAdaptor: GumbyClient) {
4545
private val telemetry = CodeTransformTelemetryManager.getInstance(project)
@@ -51,7 +51,7 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
5151
if (isCurrentlyDownloading.get()) return
5252
val result = downloadArtifact(job)
5353
if (result.artifact == null) {
54-
notifyUnableToApplyPatch(result.zipPath)
54+
notifyUnableToApplyPatch(result.zipPath, result.errorMessage)
5555
} else {
5656
displayDiffUsingPatch(result.artifact.patch, job)
5757
}
@@ -123,7 +123,7 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
123123
DownloadArtifactResult(artifact, zipPath)
124124
} catch (e: RuntimeException) {
125125
LOG.error { e.message.toString() }
126-
DownloadArtifactResult(null, zipPath)
126+
DownloadArtifactResult(null, zipPath, e.message.orEmpty())
127127
}
128128
}
129129

@@ -148,7 +148,7 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
148148
} catch (e: RuntimeException) {
149149
LOG.error { e.message.toString() }
150150
telemetryErrorMessage = "Unexpected error when downloading result ${e.localizedMessage}"
151-
DownloadArtifactResult(null, zipPath)
151+
DownloadArtifactResult(null, zipPath, e.message.orEmpty())
152152
} finally {
153153
telemetry.jobArtifactDownloadAndDeserializeTime(
154154
downloadStartTime,
@@ -158,7 +158,7 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
158158
)
159159
}
160160
} catch (e: Exception) {
161-
return DownloadArtifactResult(null, "")
161+
return DownloadArtifactResult(null, "", e.message.orEmpty())
162162
} finally {
163163
isCurrentlyDownloading.set(false)
164164
}
@@ -194,11 +194,11 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
194194
}
195195
}
196196

197-
fun notifyUnableToApplyPatch(patchPath: String) {
197+
fun notifyUnableToApplyPatch(patchPath: String, errorMessage: String) {
198198
LOG.error { "Unable to find patch for file: $patchPath" }
199199
notifyStickyWarn(
200200
message("codemodernizer.notification.warn.view_diff_failed.title"),
201-
message("codemodernizer.notification.warn.view_diff_failed.content"),
201+
message("codemodernizer.notification.warn.view_diff_failed.content", errorMessage),
202202
project,
203203
listOf(
204204
openTroubleshootingGuideNotificationAction(

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class CodeModernizerSession(
342342
createUploadUrlResponse.kmsKeyArn().orEmpty(),
343343
) { shouldStop.get() }
344344
} catch (e: Exception) {
345-
val errorMessage = "Unexpected error when uploading artifact to S3: ${e.localizedMessage}"
345+
val errorMessage = "Unexpected error when uploading artifact to S3: ${e.message}"
346346
LOG.error { errorMessage }
347347
// emit this metric here manually since we don't use callApi(), which emits its own metric
348348
telemetry.apiError(errorMessage, CodeTransformApiNames.UploadZip, createUploadUrlResponse.uploadId())
@@ -461,7 +461,7 @@ class CodeModernizerSession(
461461
result.succeeded -> CodeModernizerJobCompletedResult.JobCompletedSuccessfully(jobId)
462462

463463
// Should not happen
464-
else -> CodeModernizerJobCompletedResult.JobFailed(jobId, result.jobDetails?.reason())
464+
else -> CodeModernizerJobCompletedResult.JobFailed(jobId, result.jobDetails?.reason().orEmpty())
465465
}
466466
} catch (e: Exception) {
467467
return when (e) {
@@ -474,7 +474,7 @@ class CodeModernizerSession(
474474
LOG.error(e) { e.message.toString() }
475475
CodeModernizerJobCompletedResult.RetryableFailure(
476476
jobId,
477-
message("codemodernizer.notification.info.modernize_failed.connection_failed", e.localizedMessage),
477+
message("codemodernizer.notification.info.modernize_failed.connection_failed", e.message.orEmpty()),
478478
)
479479
}
480480
}

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/client/GumbyClient.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class GumbyClient(private val project: Project) {
206206
.connect { request -> // default connect timeout is 10s
207207
val connection = request.connection as HttpURLConnection
208208
connection.setFixedLengthStreamingMode(fileToUpload.length())
209+
connection.readTimeout = 30 * 60 * 1000 // since pre-signed URL expiration was increased to 30 minutes
209210
fileToUpload.inputStream().use { inputStream ->
210211
connection.outputStream.use {
211212
val bufferSize = 4096

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,13 @@ fun buildTransformResultChatContent(result: CodeModernizerJobCompletedResult): C
268268
message("codemodernizer.chat.message.result.partially_success")
269269
}
270270
is CodeModernizerJobCompletedResult.JobFailed -> {
271-
message("codemodernizer.chat.message.result.fail_with_known_reason", result.failureReason.orEmpty())
271+
message("codemodernizer.chat.message.result.fail_with_known_reason", result.failureReason)
272+
}
273+
is CodeModernizerJobCompletedResult.UnableToCreateJob -> {
274+
result.failureReason
275+
}
276+
is CodeModernizerJobCompletedResult.RetryableFailure -> {
277+
result.failureReason
272278
}
273279
else -> {
274280
message("codemodernizer.chat.message.result.fail")

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CodeModernizerJobCompletedResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion
88
sealed class CodeModernizerJobCompletedResult {
99
data class RetryableFailure(val jobId: JobId, val failureReason: String) : CodeModernizerJobCompletedResult()
1010
data class UnableToCreateJob(val failureReason: String, val retryable: Boolean = false) : CodeModernizerJobCompletedResult()
11-
data class JobFailed(val jobId: JobId, val failureReason: String?) : CodeModernizerJobCompletedResult()
11+
data class JobFailed(val jobId: JobId, val failureReason: String) : CodeModernizerJobCompletedResult()
1212

1313
data class JobCompletedSuccessfully(val jobId: JobId) : CodeModernizerJobCompletedResult()
1414
data class JobPartiallySucceeded(val jobId: JobId, val targetJavaVersion: JavaSdkVersion) : CodeModernizerJobCompletedResult()

plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class CodeWhispererCodeModernizerTest : CodeWhispererCodeModernizerTestBase() {
3939
fun `ArtifactHandler notifies users if patch does not exist`() = runBlocking {
4040
val handler = spy(ArtifactHandler(project, clientAdaptorSpy))
4141
val path = testCodeModernizerArtifact.zipPath
42-
doNothing().whenever(handler).notifyUnableToApplyPatch(path)
42+
doNothing().whenever(handler).notifyUnableToApplyPatch(path, "")
4343
val result = DownloadArtifactResult(null, path)
4444
doReturn(result).whenever(handler).downloadArtifact(any())
4545
handler.displayDiff(jobId)
46-
verify(handler, times(1)).notifyUnableToApplyPatch(path)
46+
verify(handler, times(1)).notifyUnableToApplyPatch(path, "")
4747
}
4848

4949
@Test
@@ -54,7 +54,7 @@ class CodeWhispererCodeModernizerTest : CodeWhispererCodeModernizerTestBase() {
5454
doReturn(result).whenever(handler).downloadArtifact(any())
5555
doNothing().whenever(handler).displayDiffUsingPatch(any(), any())
5656
handler.displayDiff(jobId)
57-
verify(handler, never()).notifyUnableToApplyPatch(path)
57+
verify(handler, never()).notifyUnableToApplyPatch(path, "")
5858
verify(handler, times(1)).displayDiffUsingPatch(testCodeModernizerArtifact.patch, jobId)
5959
}
6060

plugins/toolkit/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ codemodernizer.notification.warn.submit_feedback=Submit feedback
677677
codemodernizer.notification.warn.unable_to_start_job=Amazon Q could not begin the transformation. Try starting the transformation again. {0}
678678
codemodernizer.notification.warn.unknown_start_failure=Amazon Q could not begin the transformation. Try starting the transformation again.
679679
codemodernizer.notification.warn.unknown_status_response=Amazon Q could not complete the transformation. Try starting the transformation again.
680-
codemodernizer.notification.warn.view_diff_failed.content=Amazon Q could not download and parse the diff with your upgraded code. Try downloading it again.
680+
codemodernizer.notification.warn.view_diff_failed.content=Amazon Q could not download and parse the diff with your upgraded code. Try downloading it again. {0}
681681
codemodernizer.notification.warn.view_diff_failed.title=Failed to download and parse diff
682682
codemodernizer.notification.warn.view_summary_failed.content=Unable to display the transformation summary due to an error.
683683
codemodernizer.notification.warn.view_summary_failed.title=Unable to display transformation summary

0 commit comments

Comments
 (0)