Skip to content

Commit 6ce5a9b

Browse files
authored
fix(amazonq): add handling for new limit mechanism (#5122)
1 parent e216d55 commit 6ce5a9b

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed
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

+21-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ 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+
// BE service will throw ServiceQuota if conversation limit is reached. API Front-end will throw Throttling with this message if conversation limit is reached
69+
if (
70+
e is software.amazon.awssdk.services.codewhispererruntime.model.ServiceQuotaExceededException ||
71+
(
72+
e is software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException &&
73+
e.message?.contains("reached for this month.") == true
74+
)
75+
) {
6976
throw MonthlyConversationLimitError(errMssg, operation = FeatureDevOperation.CreateConversation.toString(), desc = null, cause = e.cause)
7077
}
7178
}
@@ -134,10 +141,19 @@ class FeatureDevService(val proxyClient: FeatureDevClient, val project: Project)
134141
errMssg = e.awsErrorDetails().errorMessage()
135142
logger.warn(e) { "StartTaskAssistCodeGeneration failed for request: ${e.requestId()}" }
136143

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
144+
// API Front-end will throw Throttling if conversation limit is reached. API Front-end monitors StartCodeGeneration for throttling
145+
if (e is software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException &&
146+
e.message?.contains("StartTaskAssistCodeGeneration reached for this month.") == true
147+
) {
148+
throw MonthlyConversationLimitError(errMssg, operation = FeatureDevOperation.StartTaskAssistCodeGeneration.toString(), desc = null, e.cause)
149+
}
150+
// BE service will throw ServiceQuota if code generation iteration limit is reached
151+
else if (e is software.amazon.awssdk.services.codewhispererruntime.model.ServiceQuotaExceededException || (
152+
e is software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException && (
153+
e.message?.contains(
154+
"limit for number of iterations on a code generation"
155+
) == true
156+
)
141157
)
142158
) {
143159
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

+32
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 =

0 commit comments

Comments
 (0)