async startTransformation()

in server/aws-lsp-codewhisperer/src/language-server/netTransform/transformHandler.ts [49:107]


    async startTransformation(userInputrequest: StartTransformRequest): Promise<StartTransformResponse> {
        var unsupportedProjects: string[] = []
        const isProject = validation.isProject(userInputrequest)
        const containsUnsupportedViews = await validation.checkForUnsupportedViews(
            userInputrequest,
            isProject,
            this.logging
        )
        if (isProject) {
            let isValid = validation.validateProject(userInputrequest, this.logging)
            if (!isValid) {
                return {
                    Error: 'NotSupported',
                    IsSupported: false,
                    ContainsUnsupportedViews: containsUnsupportedViews,
                } as StartTransformResponse
            }
        } else {
            unsupportedProjects = validation.validateSolution(userInputrequest)
        }

        const artifactManager = new ArtifactManager(
            this.workspace,
            this.logging,
            this.getWorkspacePath(userInputrequest.SolutionRootPath)
        )
        try {
            const payloadFilePath = await this.zipCodeAsync(userInputrequest, artifactManager)
            this.logging.log('Payload path: ' + payloadFilePath)

            const uploadId = await this.preTransformationUploadCode(payloadFilePath)
            const request = getCWStartTransformRequest(userInputrequest, uploadId, this.logging)
            this.logging.log('Sending request to start transform api: ' + JSON.stringify(request))
            const response = await this.serviceManager
                .getCodewhispererService()
                .codeModernizerStartCodeTransformation(request)
            this.logging.log('Received transformation job Id: ' + response?.transformationJobId)
            return getCWStartTransformResponse(
                response,
                uploadId,
                payloadFilePath,
                unsupportedProjects,
                containsUnsupportedViews
            )
        } catch (error) {
            let errorMessage = (error as Error).message ?? 'Error in StartTransformation API call'
            if (errorMessage.includes('Invalid transformation specification')) {
                errorMessage =
                    'Your profile credentials are not allow-listed or lack the necessary access. Please check your credentials.'
            }
            this.logging.log(errorMessage)
            throw new Error(errorMessage)
        } finally {
            const env = this.runtime.getConfiguration('RUNENV') ?? ''
            if (env.toUpperCase() != 'TEST') {
                artifactManager.cleanup()
            }
        }
    }