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 f556ec8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import {
prepareRepoData,
PrepareRepoDataOptions,
TelemetryHelper,
ContentLengthError,
maxRepoSizeBytes,
} from 'aws-core-vscode/amazonqFeatureDev'
import { assertTelemetry, getWorkspaceFolder, TestFolder } from 'aws-core-vscode/test'
import { fs, AmazonqCreateUpload, ZipStream } from 'aws-core-vscode/shared'
import { MetricName, Span } from 'aws-core-vscode/telemetry'
import sinon from 'sinon'
import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'
import { CurrentWsFolders } from 'aws-core-vscode/amazonq'
import { ContentLengthError, CurrentWsFolders } from 'aws-core-vscode/amazonq'
import path from 'path'

const testDevfilePrepareRepo = async (devfileEnabled: boolean) => {
Expand Down
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' })
}
}
1 change: 1 addition & 0 deletions packages/core/src/amazonq/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export { ExtensionMessage } from '../amazonq/webview/ui/commands'
export { CodeReference } from '../codewhispererChat/view/connector/connector'
export { extractAuthFollowUp } from './util/authUtils'
export { Messenger } from './commons/connector/baseMessenger'
export { ContentLengthError } from './errors'
import { FeatureContext } from '../shared/featureConfig'

/**
Expand Down
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 f556ec8

Please sign in to comment.