Skip to content

Commit dff6bc5

Browse files
committed
format
1 parent b5774fc commit dff6bc5

File tree

2 files changed

+12
-12
lines changed
  • plugins/amazonq

2 files changed

+12
-12
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ class BrowserConnector(
442442
} catch (e: Exception) {
443443
LOG.error { "Failed to perform chat tab bar action $e" }
444444
params.tabId?.let {
445-
chatCommunicationManager.sendErrorToUi(it, e, null)
445+
browser.postChat(chatCommunicationManager.getErrorUiMessage(it, e, null))
446446
}
447447
}
448448
}
@@ -500,11 +500,14 @@ class BrowserConnector(
500500
encryptionManager?.decrypt(value).orEmpty(),
501501
isPartialResult = false
502502
)
503+
if (messageToChat.contains("abc")) {
504+
throw Exception("abc err")
505+
}
503506
browser.postChat(messageToChat)
504507
chatCommunicationManager.removeInflightRequestForTab(tabId)
505508
} catch (e: Exception) {
506509
LOG.error { "Failed to send chat message $e" }
507-
chatCommunicationManager.sendErrorToUi(tabId, e, partialResultToken)
510+
browser.postChat(chatCommunicationManager.getErrorUiMessage(tabId, e, partialResultToken))
508511
}
509512

510513
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/flareChat/ChatCommunicationManager.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,25 @@ class ChatCommunicationManager {
7373
}
7474
}
7575

76-
fun sendErrorToUi(tabId: String, exception: Exception, token: String?) {
76+
fun getErrorUiMessage(tabId: String, exception: Exception, token: String?): String {
7777
token?.let {
7878
removePartialChatMessage(it)
7979
}
8080
val errorTitle = "An error occurred while processing your request."
8181
val errorMessage = "Details: ${exception.message}"
82-
val errorParams = Gson().toJsonTree(ErrorParams(tabId, null, errorMessage, errorTitle))
83-
sendErrorMessageToChatUi(CHAT_ERROR_PARAMS, tabId, errorParams, false)
84-
}
85-
86-
private fun sendErrorMessageToChatUi(command: String, tabId: String, partialChatResult: JsonElement, isPartialResult: Boolean) {
82+
val errorParams = Gson().toJson(ErrorParams(tabId, null, errorMessage, errorTitle)).toString()
8783
val uiMessage = """
8884
{
89-
"command":"$command",
85+
"command":"$CHAT_ERROR_PARAMS",
9086
"tabId": "$tabId",
91-
"params": $partialChatResult,
92-
"isPartialResult": $isPartialResult
87+
"params": "$errorParams",
88+
"isPartialResult": "true"
9389
}
9490
""".trimIndent()
95-
AsyncChatUiListener.notifyPartialMessageUpdate(uiMessage)
91+
return uiMessage
9692
}
9793

94+
9895
companion object {
9996
fun getInstance(project: Project) = project.service<ChatCommunicationManager>()
10097

0 commit comments

Comments
 (0)