Skip to content

Commit ab423a0

Browse files
committed
fix(amazonq): add handling for new limit mechanism
1 parent e216d55 commit ab423a0

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
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 Feature Dev: display limit reached error message"
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/util/FeatureDevService.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class FeatureDevService(val proxyClient: FeatureDevClient, val project: Project)
6565
errMssg = e.awsErrorDetails().errorMessage()
6666
logger.warn(e) { "Start conversation failed for request: ${e.requestId()}" }
6767

68-
if (e is software.amazon.awssdk.services.codewhispererruntime.model.ServiceQuotaExceededException) {
68+
// WB service will throw ServiceQuota if conversation limit is reached. RTS will throw Throttling with this message if conversation limit is reached
69+
if (e is software.amazon.awssdk.services.codewhispererruntime.model.ServiceQuotaExceededException || (e is software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException && e.message?.contains("reached for this month.") == true)) {
6970
throw MonthlyConversationLimitError(errMssg, operation = FeatureDevOperation.CreateConversation.toString(), desc = null, cause = e.cause)
7071
}
7172
}
@@ -134,10 +135,17 @@ class FeatureDevService(val proxyClient: FeatureDevClient, val project: Project)
134135
errMssg = e.awsErrorDetails().errorMessage()
135136
logger.warn(e) { "StartTaskAssistCodeGeneration failed for request: ${e.requestId()}" }
136137

137-
if (e is software.amazon.awssdk.services.codewhispererruntime.model.ServiceQuotaExceededException || (
138-
e is software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException && e.message?.contains(
139-
"limit for number of iterations on a code generation"
140-
) == true
138+
// RTS will throw Throttling if conversation limit is reached. RTS monitors StartCodeGeneration for throttling
139+
if (e is software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException && e.message?.contains("StartTaskAssistCodeGeneration reached for this month.") == true) {
140+
throw MonthlyConversationLimitError(errMssg, operation = FeatureDevOperation.StartTaskAssistCodeGeneration.toString(), desc = null, e.cause)
141+
}
142+
// WB service will throw ServiceQuota if code generation iteration limit is reached
143+
else if (e is software.amazon.awssdk.services.codewhispererruntime.model.ServiceQuotaExceededException || (
144+
e is software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException && (
145+
e.message?.contains(
146+
"limit for number of iterations on a code generation"
147+
) == true
148+
)
141149
)
142150
) {
143151
throw CodeIterationLimitException(operation = FeatureDevOperation.StartTaskAssistCodeGeneration.toString(), desc = null, e.cause)

plugins/amazonq/chat/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/util/FeatureDevServiceTest.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.ContentLengthE
2424
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.ExportParseException
2525
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.FeatureDevException
2626
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.FeatureDevTestBase
27+
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.MonthlyConversationLimitError
2728
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.clients.FeatureDevClient
2829
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.CodeGenerationStreamResult
2930
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.CodeReferenceGenerated
@@ -195,6 +196,37 @@ class FeatureDevServiceTest : FeatureDevTestBase() {
195196
)
196197
}
197198

199+
@Test
200+
fun `test startTaskAssistConversation throws ThrottlingException, different case`() {
201+
val exampleCWException =
202+
ThrottlingException
203+
.builder()
204+
.awsErrorDetails(
205+
AwsErrorDetails.builder().errorMessage("StartTaskAssistCodeGeneration reached for this month.").build(),
206+
).build()
207+
whenever(
208+
featureDevClient.startTaskAssistCodeGeneration(
209+
testConversationId,
210+
testUploadId,
211+
userMessage,
212+
codeGenerationId = codeGenerationId,
213+
currentCodeGenerationId = "EMPTY_CURRENT_CODE_GENERATION_ID",
214+
),
215+
).thenThrow(exampleCWException)
216+
217+
assertThatThrownBy {
218+
featureDevService.startTaskAssistCodeGeneration(
219+
testConversationId,
220+
testUploadId,
221+
userMessage,
222+
codeGenerationId = codeGenerationId,
223+
currentCodeGenerationId = "EMPTY_CURRENT_CODE_GENERATION_ID",
224+
)
225+
}.isExactlyInstanceOf(MonthlyConversationLimitError::class.java).withFailMessage(
226+
message("amazonqFeatureDev.exception.monthly_limit_error"),
227+
)
228+
}
229+
198230
@Test
199231
fun `test startTaskAssistConversation throws ServiceQuotaExceededException`() {
200232
val exampleCWException =
@@ -226,6 +258,7 @@ class FeatureDevServiceTest : FeatureDevTestBase() {
226258
)
227259
}
228260

261+
229262
@Test
230263
fun `test startTaskAssistConversation throws another CodeWhispererRuntimeException`() {
231264
val exampleCWException =

0 commit comments

Comments
 (0)