Skip to content

Commit

Permalink
fix: Fixed failure logging not to logs as IDE error for Q feature-dev (
Browse files Browse the repository at this point in the history
  • Loading branch information
kumsmrit authored Mar 12, 2024
1 parent 73fc53d commit b621414
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileChooser.FileChooser
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.wm.ToolWindowManager
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -644,7 +643,8 @@ class FeatureDevController(
}

private suspend fun modifyDefaultSourceFolder(tabId: String) {
val uri = context.project.guessProjectDir() ?: error("Cannot guess base directory for project ${context.project.name}")
val session = getSessionInfo(tabId)
val uri = session.context.projectRoot
val fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor()

val modifyFolderFollowUp = FollowUp(
Expand Down Expand Up @@ -683,7 +683,6 @@ class FeatureDevController(

logger.info { "Selected correct folder inside workspace: ${selectedFolder.path}" }

val session = getSessionInfo(tabId)
session.context.projectRoot = selectedFolder

messenger.sendAnswer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import software.amazon.awssdk.services.codewhispererruntime.model.ValidationExce
import software.amazon.awssdk.services.codewhispererstreaming.model.CodeWhispererStreamingException
import software.amazon.awssdk.services.codewhispererstreaming.model.ThrottlingException
import software.aws.toolkits.core.utils.debug
import software.aws.toolkits.core.utils.error
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.CodeIterationLimitError
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.ContentLengthError
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.FEATURE_NAME
Expand Down Expand Up @@ -43,12 +43,12 @@ fun createConversation(proxyClient: FeatureDevClient): String {

return conversationId
} catch (e: Exception) {
logger.error(e) { "$FEATURE_NAME: Failed to start conversation: ${e.message}" }
logger.warn(e) { "$FEATURE_NAME: Failed to start conversation: ${e.message}" }

var errMssg = e.message
if (e is CodeWhispererRuntimeException) {
errMssg = e.awsErrorDetails().errorMessage()
logger.error(e) { "Start conversation failed for request: ${e.requestId()}" }
logger.warn(e) { "Start conversation failed for request: ${e.requestId()}" }
}
apiError(errMssg, e.cause)
}
Expand All @@ -68,12 +68,12 @@ fun createUploadUrl(proxyClient: FeatureDevClient, conversationId: String, conte
}
return uploadUrlResponse
} catch (e: Exception) {
logger.error(e) { "$FEATURE_NAME: Failed to generate presigned url: ${e.message}" }
logger.warn(e) { "$FEATURE_NAME: Failed to generate presigned url: ${e.message}" }

var errMssg = e.message
if (e is CodeWhispererRuntimeException) {
errMssg = e.awsErrorDetails().errorMessage()
logger.error(e) { "Create UploadUrl failed for request: ${e.requestId()}" }
logger.warn(e) { "Create UploadUrl failed for request: ${e.requestId()}" }

if (e is ValidationException && e.message?.contains("Invalid contentLength") == true) {
throw ContentLengthError(message("amazonqFeatureDev.content_length.error_text"), e.cause)
Expand Down Expand Up @@ -107,12 +107,12 @@ suspend fun generatePlan(
)
return generatePlanResult
} catch (e: Exception) {
logger.error(e) { "$FEATURE_NAME: Failed to execute planning : ${e.message}" }
logger.warn(e) { "$FEATURE_NAME: Failed to execute planning : ${e.message}" }

var errMssg = e.message
if (e is CodeWhispererStreamingException) {
errMssg = e.awsErrorDetails().errorMessage()
logger.error(e) { "Generate plan failed for request: ${e.requestId()}" }
logger.warn(e) { "Generate plan failed for request: ${e.requestId()}" }

if (e is ThrottlingException && e.message?.contains("limit for number of iterations on an implementation plan") == true) {
throw PlanIterationLimitError(message("amazonqFeatureDev.approach_gen.iteration_limit.error_text"), e.cause)
Expand All @@ -135,12 +135,12 @@ fun startTaskAssistCodeGeneration(proxyClient: FeatureDevClient, conversationId:
logger.debug { "$FEATURE_NAME: Started code generation with requestId: ${startCodeGenerationResponse.responseMetadata().requestId()}" }
return startCodeGenerationResponse
} catch (e: Exception) {
logger.error(e) { "$FEATURE_NAME: Failed to execute startTaskAssistCodeGeneration ${e.message}" }
logger.warn(e) { "$FEATURE_NAME: Failed to execute startTaskAssistCodeGeneration ${e.message}" }

var errMssg = e.message
if (e is CodeWhispererRuntimeException) {
errMssg = e.awsErrorDetails().errorMessage()
logger.error(e) { "StartTaskAssistCodeGeneration failed for request: ${e.requestId()}" }
logger.warn(e) { "StartTaskAssistCodeGeneration failed for request: ${e.requestId()}" }

if (e is software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException && e.message?.contains(
"limit for number of iterations on a code generation"
Expand All @@ -165,12 +165,12 @@ fun getTaskAssistCodeGeneration(proxyClient: FeatureDevClient, conversationId: S
}
return getCodeGenerationResponse
} catch (e: Exception) {
logger.error(e) { "$FEATURE_NAME: Failed to execute GetTaskAssistCodeGeneration ${e.message}" }
logger.warn(e) { "$FEATURE_NAME: Failed to execute GetTaskAssistCodeGeneration ${e.message}" }

var errMssg = e.message
if (e is CodeWhispererRuntimeException) {
errMssg = e.awsErrorDetails().errorMessage()
logger.error(e) { "GetTaskAssistCodeGeneration failed for request: ${e.requestId()}" }
logger.warn(e) { "GetTaskAssistCodeGeneration failed for request: ${e.requestId()}" }
}
apiError(errMssg, e.cause)
}
Expand All @@ -182,12 +182,12 @@ suspend fun exportTaskAssistArchiveResult(proxyClient: FeatureDevClient, convers
exportResponse = proxyClient.exportTaskAssistResultArchive(conversationId)
logger.debug { "$FEATURE_NAME: Received export task assist result archive response" }
} catch (e: Exception) {
logger.error(e) { "$FEATURE_NAME: Failed to export archive result: ${e.message}" }
logger.warn(e) { "$FEATURE_NAME: Failed to export archive result: ${e.message}" }

var errMssg = e.message
if (e is CodeWhispererStreamingException) {
errMssg = e.awsErrorDetails().errorMessage()
logger.error(e) { "ExportTaskAssistArchiveResult failed for request: ${e.requestId()}" }
logger.warn(e) { "ExportTaskAssistArchiveResult failed for request: ${e.requestId()}" }
}
apiError(errMssg, e.cause)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util

import com.intellij.util.io.HttpRequests
import software.amazon.awssdk.utils.IoUtils
import software.aws.toolkits.core.utils.error
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.jetbrains.core.AwsClientManager
Expand Down Expand Up @@ -38,7 +37,7 @@ fun uploadArtifactToS3(url: String, fileToUpload: File, checksumSha256: String,
IoUtils.copy(fileToUpload.inputStream(), connection.outputStream)
}
} catch (err: Exception) {
logger.error(err) { "$FEATURE_NAME: Failed to upload code to S3" }
logger.warn(err) { "$FEATURE_NAME: Failed to upload code to S3" }
uploadCodeError()
}
}
Expand Down

0 comments on commit b621414

Please sign in to comment.