diff --git a/packages/amazonq/.changes/next-release/Bug Fix-6b8cf110-2050-4ac1-8a3b-637ed54980cf.json b/packages/amazonq/.changes/next-release/Bug Fix-6b8cf110-2050-4ac1-8a3b-637ed54980cf.json new file mode 100644 index 00000000000..011b5eb6c62 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-6b8cf110-2050-4ac1-8a3b-637ed54980cf.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Amazon Q /doc: Fix uploading file method throwing incorrect workspace too large error message" +} diff --git a/packages/core/src/amazonq/errors.ts b/packages/core/src/amazonq/errors.ts new file mode 100644 index 00000000000..cf45cb61265 --- /dev/null +++ b/packages/core/src/amazonq/errors.ts @@ -0,0 +1,13 @@ +/*! + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + * + */ + +import { ToolkitError } from '../shared/errors' + +export class CommonAmazonQContentLengthError extends ToolkitError { + constructor(message: string) { + super(message, { code: 'CommonAmazonQContentLengthError' }) + } +} diff --git a/packages/core/src/amazonq/util/files.ts b/packages/core/src/amazonq/util/files.ts index 848e6c5d807..eef133c514f 100644 --- a/packages/core/src/amazonq/util/files.ts +++ b/packages/core/src/amazonq/util/files.ts @@ -12,7 +12,7 @@ import { getWorkspaceFoldersByPrefixes, } from '../../shared/utilities/workspaceUtils' -import { ContentLengthError, PrepareRepoFailedError } from '../../amazonqFeatureDev/errors' +import { PrepareRepoFailedError } from '../../amazonqFeatureDev/errors' import { getLogger } from '../../shared/logger/logger' import { maxFileSizeBytes } from '../../amazonqFeatureDev/limits' import { CurrentWsFolders, DeletedFileInfo, NewFileInfo, NewFileZipContents } from '../../amazonqDoc/types' @@ -28,6 +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' export const SvgFileExtension = '.svg' @@ -186,7 +187,7 @@ export async function prepareRepoData( } catch (error) { getLogger().debug(`featureDev: Failed to prepare repo: ${error}`) if (error instanceof ToolkitError && error.code === 'ContentLengthError') { - throw new ContentLengthError() + throw new CommonAmazonQContentLengthError(error.message) } throw new PrepareRepoFailedError() } diff --git a/packages/core/src/amazonqDoc/session/session.ts b/packages/core/src/amazonqDoc/session/session.ts index f132799d8ae..73f725118ea 100644 --- a/packages/core/src/amazonqDoc/session/session.ts +++ b/packages/core/src/amazonqDoc/session/session.ts @@ -30,6 +30,8 @@ import fs from '../../shared/fs/fs' 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' export class Session { private _state?: SessionState | Omit @@ -126,28 +128,35 @@ export class Session { return this.nextInteraction(msg, mode, folderPath) } private async nextInteraction(msg: string, mode: Mode, folderPath?: string) { - const resp = await this.state.interact({ - task: this.task, - msg, - fs: this.config.fs, - mode: mode, - folderPath: folderPath, - messenger: this.messenger, - telemetry: this.telemetry, - tokenSource: this.state.tokenSource, - uploadHistory: this.state.uploadHistory, - }) + try { + const resp = await this.state.interact({ + task: this.task, + msg, + fs: this.config.fs, + mode: mode, + folderPath: folderPath, + messenger: this.messenger, + telemetry: this.telemetry, + tokenSource: this.state.tokenSource, + uploadHistory: this.state.uploadHistory, + }) + + if (resp.nextState) { + if (!this.state?.tokenSource?.token.isCancellationRequested) { + this.state?.tokenSource?.cancel() + } - if (resp.nextState) { - if (!this.state?.tokenSource?.token.isCancellationRequested) { - this.state?.tokenSource?.cancel() + // Move to the next state + this._state = resp.nextState } - // Move to the next state - this._state = resp.nextState + return resp.interaction + } catch (e) { + if (e instanceof CommonAmazonQContentLengthError) { + throw new ContentLengthError() + } + throw e } - - return resp.interaction } public async updateFilesPaths( diff --git a/packages/core/src/amazonqFeatureDev/session/session.ts b/packages/core/src/amazonqFeatureDev/session/session.ts index 3ce3000757e..447d078d3cb 100644 --- a/packages/core/src/amazonqFeatureDev/session/session.ts +++ b/packages/core/src/amazonqFeatureDev/session/session.ts @@ -14,7 +14,7 @@ import { type SessionStateConfig, UpdateFilesPathsParams, } from '../../amazonq/commons/types' -import { ConversationIdNotFoundError } from '../errors' +import { ContentLengthError, ConversationIdNotFoundError } from '../errors' import { featureDevChat, referenceLogText, featureDevScheme } from '../constants' import fs from '../../shared/fs/fs' import { FeatureDevClient } from '../client/featureDev' @@ -33,6 +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' export class Session { private _state?: SessionState | Omit private task: string = '' @@ -137,25 +138,32 @@ export class Session { } private async nextInteraction(msg: string) { - const resp = await this.state.interact({ - task: this.task, - msg, - fs: this.config.fs, - messenger: this.messenger, - telemetry: this.telemetry, - tokenSource: this.state.tokenSource, - uploadHistory: this.state.uploadHistory, - }) + try { + const resp = await this.state.interact({ + task: this.task, + msg, + fs: this.config.fs, + messenger: this.messenger, + telemetry: this.telemetry, + tokenSource: this.state.tokenSource, + uploadHistory: this.state.uploadHistory, + }) - if (resp.nextState) { - if (!this.state?.tokenSource?.token.isCancellationRequested) { - this.state?.tokenSource?.cancel() + if (resp.nextState) { + if (!this.state?.tokenSource?.token.isCancellationRequested) { + this.state?.tokenSource?.cancel() + } + // Move to the next state + this._state = resp.nextState } - // Move to the next state - this._state = resp.nextState - } - return resp.interaction + return resp.interaction + } catch (e) { + if (e instanceof CommonAmazonQContentLengthError) { + throw new ContentLengthError() + } + throw e + } } public async updateFilesPaths(params: UpdateFilesPathsParams) {