Skip to content

Commit

Permalink
chore: update according to the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinDing1 committed Feb 25, 2025
1 parent 60b342b commit 137122e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/amazonq/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
*
*/

/**
* Shared error type for content length validation.
* When thrown from common components, individual agents can catch and transform this error
* to provide their own customized error messages.
*/
import { ToolkitError } from '../shared/errors'

export class CommonAmazonQContentLengthError extends ToolkitError {
export class ContentLengthError extends ToolkitError {
constructor(message: string) {
super(message, { code: 'CommonAmazonQContentLengthError' })
super(message, { code: 'ContentLengthError' })
}
}
6 changes: 3 additions & 3 deletions packages/core/src/amazonq/util/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ZipStream } from '../../shared/utilities/zipStream'
import { isPresent } from '../../shared/utilities/collectionUtils'
import { AuthUtil } from '../../codewhisperer/util/authUtil'
import { TelemetryHelper } from '../util/telemetryHelper'
import { CommonAmazonQContentLengthError } from '../errors'
import { ContentLengthError } from '../errors'

export const SvgFileExtension = '.svg'

Expand Down Expand Up @@ -185,9 +185,9 @@ export async function prepareRepoData(
zipFileChecksum: zipResult.hash,
}
} catch (error) {
getLogger().debug(`featureDev: Failed to prepare repo: ${error}`)
getLogger().debug(`Failed to prepare repo: ${error}`)
if (error instanceof ToolkitError && error.code === 'ContentLengthError') {
throw new CommonAmazonQContentLengthError(error.message)
throw new ContentLengthError(error.message)
}
throw new PrepareRepoFailedError()
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/amazonqDoc/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import globals from '../../shared/extensionGlobals'
import { extensionVersion } from '../../shared/vscode/env'
import { getLogger } from '../../shared/logger/logger'
import { ContentLengthError } from '../errors'
import { CommonAmazonQContentLengthError } from '../../amazonq/errors'
import { ContentLengthError as CommonAmazonQContentLengthError } from '../../amazonq/errors'

export class Session {
private _state?: SessionState | Omit<SessionState, 'uploadId'>
Expand Down Expand Up @@ -153,6 +153,7 @@ export class Session {
return resp.interaction
} catch (e) {
if (e instanceof CommonAmazonQContentLengthError) {
getLogger().debug(`Content length validation failed: ${e.message}`)
throw new ContentLengthError()
}
throw e
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/amazonqFeatureDev/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { UpdateAnswerMessage } from '../../amazonq/commons/connector/connectorMe
import { FollowUpTypes } from '../../amazonq/commons/types'
import { SessionConfig } from '../../amazonq/commons/session/sessionConfigFactory'
import { Messenger } from '../../amazonq/commons/connector/baseMessenger'
import { CommonAmazonQContentLengthError } from '../../amazonq/errors'
import { ContentLengthError as CommonAmazonQContentLengthError } from '../../amazonq/errors'
export class Session {
private _state?: SessionState | Omit<SessionState, 'uploadId'>
private task: string = ''
Expand Down Expand Up @@ -160,6 +160,7 @@ export class Session {
return resp.interaction
} catch (e) {
if (e instanceof CommonAmazonQContentLengthError) {
getLogger().debug(`Content length validation failed: ${e.message}`)
throw new ContentLengthError()
}
throw e
Expand Down

0 comments on commit 137122e

Please sign in to comment.