Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Amazon Q: Fix profile selection errors and EDT threading violations (#6039)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat

import com.google.gson.Gson
import com.google.gson.JsonObject
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
Expand Down Expand Up @@ -203,10 +204,13 @@ class ChatCommunicationManager(private val project: Project, private val cs: Cor
project.messageBus.syncPublisher(QRegionProfileSelectedListener.TOPIC)
.onProfileSelected(project, QRegionProfileManager.getInstance().activeProfile(project))
} else {
QRegionProfileDialog(
project,
selectedProfile = null
).show()
// Wrap in runInEdt to ensure dialog is shown on Event Dispatch Thread
runInEdt {
QRegionProfileDialog(
project,
selectedProfile = null
).show()
}
}

return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,21 @@ class QRegionProfileDialog(

combo.proposeModelUpdate { model ->
try {
QRegionProfileManager.getInstance().listRegionProfiles(project)?.forEach {
model.addElement(it)
} ?: error("Attempted to fetch profiles while there does not exist")

val profiles = QRegionProfileManager.getInstance().listRegionProfiles(project)
// Handle empty/null profiles gracefully instead of throwing
if (profiles.isNullOrEmpty()) {
val conn = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance()) as? AwsBearerTokenConnection
Telemetry.amazonq.didSelectProfile.use { span ->
span.source(QProfileSwitchIntent.User.value)
.amazonQProfileRegion("not-set")
.ssoRegion(conn?.region)
.credentialStartUrl(conn?.startUrl)
.result(MetricResult.Failed)
.reason("No profiles available")
}
return@proposeModelUpdate
}
profiles.forEach { model.addElement(it) }
model.selectedItem = selectedProfile
} catch (e: Exception) {
val conn = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance()) as? AwsBearerTokenConnection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ class QRegionProfileManager : PersistentStateComponent<QProfileState>, Disposabl
if (mappedProfiles.size == 1) {
switchProfile(project, mappedProfiles.first(), intent = QProfileSwitchIntent.Update)
}
mappedProfiles.takeIf { it.isNotEmpty() }?.also {
connectionIdToProfileCount[connection.id] = it.size
} ?: error("You don't have access to the resource")
// Return null for empty profiles instead of throwing, let callers handle gracefully
if (mappedProfiles.isNotEmpty()) {
connectionIdToProfileCount[connection.id] = mappedProfiles.size
}
mappedProfiles.takeIf { it.isNotEmpty() }
} catch (e: Exception) {
if (e is AccessDeniedException) {
LOG.warn { "Failed to list region profiles: ${e.message}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ class DefaultCodeWhispererModelConfigurator(
calculateIfIamIdentityCenterConnection(project) {
// 1. fetch all profiles, invoke fetch customizations API and get result for each profile and aggregate all the results
val profiles = QRegionProfileManager.getInstance().listRegionProfiles(project)
?: error("Attempted to fetch profiles while there does not exist")
// Return empty list when no profiles available instead of throwing
if (profiles.isNullOrEmpty()) {
return@calculateIfIamIdentityCenterConnection emptyList()
}

val customizations = profiles.flatMap { profile ->
runCatching {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package software.aws.toolkits.jetbrains.ui

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.progress.EmptyProgressIndicator
import com.intellij.openapi.progress.ProgressIndicator
Expand Down Expand Up @@ -92,7 +93,8 @@ class AsyncComboBox<T> private constructor(
currentIndicator?.cancel()
loading.set(true)
removeAllItems()
repaint()
// Ensure repaint happens on EDT for thread safety
ApplicationManager.getApplication().invokeLater { repaint() }
val indicator = EmptyProgressIndicator(ModalityState.any()).also {
currentIndicator = it
}
Expand All @@ -105,7 +107,8 @@ class AsyncComboBox<T> private constructor(
newModel.invoke(delegatedComboBoxModel(indicator))
}.invokeOnCompletion {
loading.set(false)
repaint()
// Ensure repaint happens on EDT for thread safety
ApplicationManager.getApplication().invokeLater { repaint() }
}
},
indicator
Expand Down