diff --git a/packages/core/src/amazonqGumby/chat/controller/controller.ts b/packages/core/src/amazonqGumby/chat/controller/controller.ts index ae277ca24f9..90706cbf731 100644 --- a/packages/core/src/amazonqGumby/chat/controller/controller.ts +++ b/packages/core/src/amazonqGumby/chat/controller/controller.ts @@ -580,10 +580,14 @@ export class GumbyController { return } const fileContents = await fs.readFileText(fileUri[0].fsPath) - const isValidFile = await validateCustomVersionsFile(fileContents) + const missingKey = await validateCustomVersionsFile(fileContents) - if (!isValidFile) { - this.messenger.sendUnrecoverableErrorResponse('invalid-custom-versions-file', message.tabID) + if (missingKey) { + this.messenger.sendMessage( + CodeWhispererConstants.invalidCustomVersionsFileMessage(missingKey), + message.tabID, + 'ai-prompt' + ) return } this.messenger.sendMessage(CodeWhispererConstants.receivedValidConfigFileMessage, message.tabID, 'ai-prompt') diff --git a/packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts b/packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts index 59c144a8605..409ee89ab04 100644 --- a/packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts +++ b/packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts @@ -50,7 +50,6 @@ export type UnrecoverableErrorType = | 'job-start-failed' | 'unsupported-source-db' | 'unsupported-target-db' - | 'invalid-custom-versions-file' | 'error-parsing-sct-file' | 'invalid-zip-no-sct-file' | 'invalid-from-to-jdk' @@ -453,9 +452,6 @@ export class Messenger { case 'unsupported-target-db': message = CodeWhispererConstants.invalidMetadataFileUnsupportedTargetDB break - case 'invalid-custom-versions-file': - message = CodeWhispererConstants.invalidCustomVersionsFileMessage - break case 'error-parsing-sct-file': message = CodeWhispererConstants.invalidMetadataFileErrorParsing break diff --git a/packages/core/src/codewhisperer/models/constants.ts b/packages/core/src/codewhisperer/models/constants.ts index 4db98727765..3e72ca1de19 100644 --- a/packages/core/src/codewhisperer/models/constants.ts +++ b/packages/core/src/codewhisperer/models/constants.ts @@ -582,8 +582,8 @@ export const invalidMetadataFileUnsupportedSourceDB = export const invalidMetadataFileUnsupportedTargetDB = 'I can only convert SQL for migrations to Aurora PostgreSQL or Amazon RDS for PostgreSQL target databases. The provided .sct file indicates another target database for this migration.' -export const invalidCustomVersionsFileMessage = - "I wasn't able to parse the dependency upgrade file. Check that it's configured properly and try again. For an example of the required dependency upgrade file format, see the [documentation](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/code-transformation.html#dependency-upgrade-file)." +export const invalidCustomVersionsFileMessage = (missingKey: string) => + `The dependency upgrade file provided is missing required field \`${missingKey}\`. Check that it is configured properly and try again. For an example of the required dependency upgrade file format, see the [documentation](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/code-transformation.html#dependency-upgrade-file).` export const invalidMetadataFileErrorParsing = "It looks like the .sct file you provided isn't valid. Make sure that you've uploaded the .zip file you retrieved from your schema conversion in AWS DMS." diff --git a/packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts b/packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts index 2ec6fdb7c37..6aad4fd15f6 100644 --- a/packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts +++ b/packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts @@ -117,15 +117,16 @@ export async function parseBuildFile() { return undefined } +// return the first missing key in the custom versions file, or undefined if all required keys are present export async function validateCustomVersionsFile(fileContents: string) { - const requiredKeys = ['dependencyManagement:', 'identifier:', 'targetVersion:'] + const requiredKeys = ['dependencyManagement', 'identifier', 'targetVersion', 'originType'] for (const key of requiredKeys) { if (!fileContents.includes(key)) { getLogger().info(`CodeTransformation: .YAML file is missing required key: ${key}`) - return false + return key } } - return true + return undefined } export async function validateSQLMetadataFile(fileContents: string, message: any) { diff --git a/packages/core/src/test/codewhisperer/commands/transformByQ.test.ts b/packages/core/src/test/codewhisperer/commands/transformByQ.test.ts index 554d24c855a..8d2017100b9 100644 --- a/packages/core/src/test/codewhisperer/commands/transformByQ.test.ts +++ b/packages/core/src/test/codewhisperer/commands/transformByQ.test.ts @@ -571,14 +571,14 @@ dependencyManagement: }) it(`WHEN validateCustomVersionsFile on fully valid .yaml file THEN passes validation`, async function () { - const isValidFile = await validateCustomVersionsFile(validCustomVersionsFile) - assert.strictEqual(isValidFile, true) + const missingKey = await validateCustomVersionsFile(validCustomVersionsFile) + assert.strictEqual(missingKey, undefined) }) it(`WHEN validateCustomVersionsFile on invalid .yaml file THEN fails validation`, async function () { const invalidFile = validCustomVersionsFile.replace('dependencyManagement', 'invalidKey') - const isValidFile = await validateCustomVersionsFile(invalidFile) - assert.strictEqual(isValidFile, false) + const missingKey = await validateCustomVersionsFile(invalidFile) + assert.strictEqual(missingKey, 'dependencyManagement') }) it(`WHEN validateMetadataFile on fully valid .sct file THEN passes validation`, async function () {