Skip to content

Commit 9105243

Browse files
committed
call if
1 parent 8223470 commit 9105243

File tree

2 files changed

+22
-18
lines changed
  • plugins/amazonq
    • chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq
    • shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/profile

2 files changed

+22
-18
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/QLoginWebview.kt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -264,23 +264,6 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
264264
// TODO: pass "REAUTH" if connection expires
265265
// Perform the potentially blocking AWS call outside the EDT to fetch available region profiles.
266266
ApplicationManager.getApplication().executeOnPooledThread {
267-
var errorMessage: String? = null
268-
val profiles: List<QRegionProfile> = try {
269-
QRegionProfileManager.getInstance().listRegionProfiles(project).orEmpty()
270-
} catch (e: Exception) {
271-
errorMessage = e.message
272-
LOG.warn { "Failed to call listRegionProfiles API" }
273-
val qConn = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance())
274-
Telemetry.amazonq.didSelectProfile.use { span ->
275-
span.source(QProfileSwitchIntent.Auth.value)
276-
.amazonQProfileRegion(QRegionProfileManager.getInstance().activeProfile(project)?.region ?: "not-set")
277-
.ssoRegion((qConn as? AwsBearerTokenConnection)?.region)
278-
.credentialStartUrl((qConn as? AwsBearerTokenConnection)?.startUrl)
279-
.result(MetricResult.Failed)
280-
.reason(e.message)
281-
}
282-
emptyList()
283-
}
284267

285268
val stage = if (isQExpired(project)) {
286269
"REAUTH"
@@ -290,6 +273,27 @@ class QWebviewBrowser(val project: Project, private val parentDisposable: Dispos
290273
"START"
291274
}
292275

276+
var errorMessage: String? = null
277+
var profiles: List<QRegionProfile> = emptyList()
278+
279+
if (stage == "PROFILE_SELECT") {
280+
try {
281+
profiles = QRegionProfileManager.getInstance().listRegionProfiles(project).orEmpty()
282+
} catch (e: Exception) {
283+
errorMessage = e.message
284+
LOG.warn { "Failed to call listRegionProfiles API" }
285+
val qConn = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance())
286+
Telemetry.amazonq.didSelectProfile.use { span ->
287+
span.source(QProfileSwitchIntent.Auth.value)
288+
.amazonQProfileRegion(QRegionProfileManager.getInstance().activeProfile(project)?.region ?: "not-set")
289+
.ssoRegion((qConn as? AwsBearerTokenConnection)?.region)
290+
.credentialStartUrl((qConn as? AwsBearerTokenConnection)?.startUrl)
291+
.result(MetricResult.Failed)
292+
.reason(e.message)
293+
}
294+
}
295+
}
296+
293297
val jsonData = """
294298
{
295299
stage: '$stage',

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/profile/QRegionProfileManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class QRegionProfileManager : PersistentStateComponent<QProfileState>, Disposabl
7474
.awsClient<CodeWhispererRuntimeClient>()
7575
.listAvailableProfilesPaginator {}
7676
.profiles()
77-
.map { p -> QRegionProfile(arn = p.arn(), profileName = p.profileName()) }
77+
.map { p -> QRegionProfile(arn = p.arn(), profileName = p.profileName()?: "<no name>") }
7878
}
7979
if (mappedProfiles.size == 1) {
8080
switchProfile(project, mappedProfiles.first(), intent = QProfileSwitchIntent.Update)

0 commit comments

Comments
 (0)