Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Amazon Q Feature Dev: Add error messages when the upload URL expires"
}
1 change: 1 addition & 0 deletions packages/core/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
"AWS.amazonq.featureDev.error.codeGen.denyListedError": "I'm sorry, I'm having trouble generating your code and can't continue at the moment. Please try again later, and share feedback to help me improve.",
"AWS.amazonq.featureDev.error.codeGen.default": "I'm sorry, I ran into an issue while trying to generate your code. Please try again.",
"AWS.amazonq.featureDev.error.codeGen.timeout": "Code generation did not finish within the expected time",
"AWS.amazonq.featureDev.error.uploadURLExpired": "I’m sorry, I wasn’t able to generate code. A connection timed out or became unavailable. Please try again or check the following:\n\n- Exclude non-essential files in your workspace’s `.gitignore.`\n\n- Check that your network connection is stable.",
"AWS.amazonq.featureDev.error.workspaceFolderNotFoundError": "I couldn't find a workspace folder. Open a workspace, and then open a new chat tab and enter /dev to start discussing your code task with me.",
"AWS.amazonq.featureDev.error.selectedFolderNotInWorkspaceFolderError": "The folder you chose isn't in your open workspace folder. You can add this folder to your workspace, or choose a folder in your open workspace.",
"AWS.amazonq.featureDev.error.userMessageNotFoundError": "It looks like you didn't provide an input. Please enter your message in the text bar.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SelectedFolderNotInWorkspaceFolderError,
TabIdNotFoundError,
UploadCodeError,
UploadURLExpired,
UserMessageNotFoundError,
WorkspaceFolderNotFoundError,
ZipFileError,
Expand Down Expand Up @@ -280,6 +281,14 @@ export class FeatureDevController {
],
})
break
case UploadURLExpired.errorName:
this.messenger.sendAnswer({
type: 'answer',
tabID: message.tabID,
message: err.message,
canBeVoted: true,
})
break
default:
if (isDenyListedError || this.retriesRemaining(session) === 0) {
defaultMessage = i18n('AWS.amazonq.featureDev.error.codeGen.denyListedError')
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/amazonqFeatureDev/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export class UploadCodeError extends ToolkitError {
}
}

export class UploadURLExpired extends ToolkitError {
static errorName = 'UploadURLExpired'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make more sense to pass in to the name field, adjacent to the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is following existing pattern.

Copy link
Contributor

@nkomonen-amazon nkomonen-amazon Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those existing uses are incorrect, they are duplicating the existing name property. If you don't want to refactor that in this PR you can follow up and we can merge this now

constructor() {
super(i18n('AWS.amazonq.featureDev.error.uploadURLExpired'), { code: 'UploadURLExpired' })
}
}

export class IllegalStateTransition extends ToolkitError {
constructor() {
super(i18n('AWS.amazonq.featureDev.error.illegalStateTransition'), { code: 'IllegalStateTransition' })
Expand Down
18 changes: 14 additions & 4 deletions packages/core/src/amazonqFeatureDev/util/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import request, { RequestError } from '../../shared/request'
import { getLogger } from '../../shared/logger/logger'
import { featureName } from '../constants'

import { UploadCodeError } from '../errors'
import { UploadCodeError, UploadURLExpired } from '../errors'
import { ToolkitError } from '../../shared'
import { i18n } from '../../shared/i18n-helper'

/**
* uploadCode
Expand All @@ -30,8 +32,16 @@ export async function uploadCode(url: string, buffer: Buffer, checksumSha256: st
}).response
} catch (e: any) {
getLogger().error(`${featureName}: failed to upload code to s3: ${(e as Error).message}`)
throw new UploadCodeError(
e instanceof RequestError ? `${e.response.status}: ${e.response.statusText}` : 'Unknown'
)
if (e instanceof RequestError) {
switch (e.response.status) {
case 403:
throw new UploadURLExpired()
default:
throw new UploadCodeError(
e instanceof RequestError ? `${e.response.status}: ${e.response.statusText}` : 'Unknown'
)
}
}
throw ToolkitError.chain(e, i18n('AWS.amazonq.featureDev.error.codeGen.default'))
}
}
Loading