Skip to content

Commit 5dfc8c5

Browse files
authored
refactor(amazonqFeatureDev): refactor error message and include backfill for error name (#5357)
* refactor(amazonqFeatureDev): refactor error message and include backfill for error name Co-authored-by: Thiago Verney <[email protected]>
1 parent 690378d commit 5dfc8c5

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q /dev: update error message for code gen timeout and include backfill for error name"
4+
}

packages/core/src/amazonqFeatureDev/controllers/chat/controller.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export class FeatureDevController {
220220
const isDenyListedError = denyListedErrors.some((err) => errorMessage.includes(err))
221221

222222
switch (err.code) {
223-
case ContentLengthError.name:
223+
case ContentLengthError.errorName:
224224
this.messenger.sendAnswer({
225225
type: 'answer',
226226
tabID: message.tabID,
@@ -238,11 +238,11 @@ export class FeatureDevController {
238238
],
239239
})
240240
break
241-
case MonthlyConversationLimitError.name:
241+
case MonthlyConversationLimitError.errorName:
242242
this.messenger.sendMonthlyLimitError(message.tabID)
243243
break
244244

245-
case PlanIterationLimitError.name:
245+
case PlanIterationLimitError.errorName:
246246
this.messenger.sendAnswer({
247247
type: 'answer',
248248
tabID: message.tabID,
@@ -266,23 +266,23 @@ export class FeatureDevController {
266266
})
267267
break
268268

269-
case FeatureDevServiceError.name:
270-
case UploadCodeError.name:
271-
case UserMessageNotFoundError.name:
272-
case TabIdNotFoundError.name:
273-
case PrepareRepoFailedError.name:
269+
case FeatureDevServiceError.errorName:
270+
case UploadCodeError.errorName:
271+
case UserMessageNotFoundError.errorName:
272+
case TabIdNotFoundError.errorName:
273+
case PrepareRepoFailedError.errorName:
274274
this.messenger.sendErrorMessage(
275275
errorMessage,
276276
message.tabID,
277277
this.retriesRemaining(session),
278278
session?.conversationIdUnsafe
279279
)
280280
break
281-
case PromptRefusalException.name:
282-
case ZipFileError.name:
281+
case PromptRefusalException.errorName:
282+
case ZipFileError.errorName:
283283
this.messenger.sendErrorMessage(errorMessage, message.tabID, 0, session?.conversationIdUnsafe, true)
284284
break
285-
case CodeIterationLimitError.name:
285+
case CodeIterationLimitError.errorName:
286286
this.messenger.sendAnswer({
287287
type: 'answer',
288288
tabID: message.tabID,

packages/core/src/amazonqFeatureDev/errors.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export class ConversationIdNotFoundError extends ToolkitError {
1616
}
1717

1818
export class TabIdNotFoundError extends ToolkitError {
19+
static errorName = 'TabIdNotFoundError'
20+
1921
constructor() {
2022
super(`I'm sorry, I'm having technical difficulties at the moment. Please try again.`, {
2123
code: 'TabIdNotFound',
@@ -41,6 +43,7 @@ export class WorkspaceFolderNotFoundError extends ToolkitError {
4143
}
4244

4345
export class UserMessageNotFoundError extends ToolkitError {
46+
static errorName = 'UserMessageNotFoundError'
4447
constructor() {
4548
super(`It looks like you didn't provide an input. Please enter your message in the text bar.`, {
4649
code: 'MessageNotFound',
@@ -60,6 +63,7 @@ export class SelectedFolderNotInWorkspaceFolderError extends ToolkitError {
6063
}
6164

6265
export class PromptRefusalException extends ToolkitError {
66+
static errorName = 'PromptRefusalException'
6367
constructor() {
6468
super(
6569
'I\'m sorry, I can\'t generate code for your request. Please make sure your message and code files comply with the <a href="https://aws.amazon.com/machine-learning/responsible-ai/policy/">AWS Responsible AI Policy.</a>',
@@ -71,12 +75,14 @@ export class PromptRefusalException extends ToolkitError {
7175
}
7276

7377
export class FeatureDevServiceError extends ToolkitError {
78+
static errorName = 'FeatureDevServiceError'
7479
constructor(message: string, code: string) {
7580
super(message, { code })
7681
}
7782
}
7883

7984
export class PrepareRepoFailedError extends ToolkitError {
85+
static errorName = 'PrepareRepoFailedError'
8086
constructor() {
8187
super('Sorry, I ran into an issue while trying to upload your code. Please try again.', {
8288
code: 'PrepareRepoFailed',
@@ -85,6 +91,7 @@ export class PrepareRepoFailedError extends ToolkitError {
8591
}
8692

8793
export class UploadCodeError extends ToolkitError {
94+
static errorName = 'UploadCodeError'
8895
constructor(statusCode: string) {
8996
super(uploadCodeError, { code: `UploadCode-${statusCode}` })
9097
}
@@ -97,41 +104,46 @@ export class IllegalStateTransition extends ToolkitError {
97104
}
98105

99106
export class ContentLengthError extends ToolkitError {
107+
static errorName = 'ContentLengthError'
100108
constructor() {
101109
super(
102110
'The folder you selected is too large for me to use as context. Please choose a smaller folder to work on. For more information on quotas, see the <a href="https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/software-dev.html#quotas" target="_blank">Amazon Q Developer documentation.</a>',
103-
{ code: 'ContentLengthError' }
111+
{ code: ContentLengthError.errorName }
104112
)
105113
}
106114
}
107115

108116
export class ZipFileError extends ToolkitError {
117+
static errorName = 'ZipFileError'
109118
constructor() {
110-
super('The zip file is corrupted', { code: 'ZipFileError' })
119+
super('The zip file is corrupted', { code: ZipFileError.errorName })
111120
}
112121
}
113122

114123
export class PlanIterationLimitError extends ToolkitError {
124+
static errorName = 'PlanIterationLimitError'
115125
constructor() {
116126
super(
117127
'Sorry, you\'ve reached the quota for number of iterations on an implementation plan. You can generate code for this task or discuss a new plan. For more information on quotas, see the <a href="https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/software-dev.html#quotas">Amazon Q Developer documentation</a>.',
118-
{ code: 'PlanIterationLimitError' }
128+
{ code: PlanIterationLimitError.errorName }
119129
)
120130
}
121131
}
122132

123133
export class CodeIterationLimitError extends ToolkitError {
134+
static errorName = 'CodeIterationLimitError'
124135
constructor() {
125136
super(
126137
'Sorry, you\'ve reached the quota for number of iterations on code generation. You can insert this code in your files or discuss a new plan. For more information on quotas, see the <a href="https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/software-dev.html#quotas" target="_blank">Amazon Q Developer documentation.</a>',
127-
{ code: 'CodeIterationLimitError' }
138+
{ code: CodeIterationLimitError.errorName }
128139
)
129140
}
130141
}
131142

132143
export class MonthlyConversationLimitError extends ToolkitError {
144+
static errorName = 'MonthlyConversationLimitError'
133145
constructor(message: string) {
134-
super(message, { code: 'MonthlyConversationLimitError' })
146+
super(message, { code: MonthlyConversationLimitError.errorName })
135147
}
136148
}
137149

packages/core/src/amazonqFeatureDev/session/sessionState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ abstract class CodeGenBase {
326326
}
327327
if (!this.tokenSource.token.isCancellationRequested) {
328328
// still in progress
329-
const errorMessage = 'Code generation did not finish withing the expected time'
329+
const errorMessage = 'Code generation did not finish within the expected time'
330330
throw new ToolkitError(errorMessage, { code: 'CodeGenTimeout' })
331331
}
332332
return {

0 commit comments

Comments
 (0)