File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -563,7 +563,13 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
563563 this . clineMessages . push ( message )
564564 const provider = this . providerRef . deref ( )
565565 // Send only the new message instead of the entire state
566- await provider ?. postMessageToWebview ( { type : "messageCreated" , clineMessage : message } )
566+ if ( provider ) {
567+ try {
568+ await provider . postMessageToWebview ( { type : "messageCreated" , clineMessage : message } )
569+ } catch ( error ) {
570+ // provider.postMessageToWebview already logs; leave as non-fatal
571+ }
572+ }
567573 this . emit ( RooCodeEventName . Message , { action : "created" , message } )
568574 await this . saveClineMessages ( )
569575
@@ -585,7 +591,13 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
585591
586592 private async updateClineMessage ( message : ClineMessage ) {
587593 const provider = this . providerRef . deref ( )
588- await provider ?. postMessageToWebview ( { type : "messageUpdated" , clineMessage : message } )
594+ if ( provider ) {
595+ try {
596+ await provider . postMessageToWebview ( { type : "messageUpdated" , clineMessage : message } )
597+ } catch ( error ) {
598+ // provider.postMessageToWebview already logs; leave as non-fatal
599+ }
600+ }
589601 this . emit ( RooCodeEventName . Message , { action : "updated" , message } )
590602
591603 const shouldCaptureMessage = message . partial !== true && CloudService . isEnabled ( )
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ import axios from "axios"
99import pWaitFor from "p-wait-for"
1010import * as vscode from "vscode"
1111
12+ // Small delay used for incremental message delivery to the webview
13+ const INCREMENTAL_SEND_DELAY_MS = 10
14+
1215import {
1316 type TaskProviderLike ,
1417 type TaskProviderEvents ,
@@ -888,7 +891,15 @@ export class ClineProvider
888891 }
889892
890893 public async postMessageToWebview ( message : ExtensionMessage ) {
891- await this . view ?. webview . postMessage ( message )
894+ try {
895+ await this . view ?. webview . postMessage ( message )
896+ } catch ( error ) {
897+ // Guard against unhandled promise rejections from webview messaging
898+ const errMsg =
899+ error instanceof Error ? error . message : typeof error === "string" ? error : JSON . stringify ( error )
900+ this . log ( `[postMessageToWebview] failed to post message '${ message . type } ': ${ errMsg } ` )
901+ // Non-fatal: continue without throwing to avoid crashing extension host
902+ }
892903 }
893904
894905 private async getHMRHtmlContent ( webview : vscode . Webview ) : Promise < string > {
@@ -1564,7 +1575,7 @@ export class ClineProvider
15641575 for ( const message of currentCline . clineMessages ) {
15651576 await this . postMessageToWebview ( { type : "messageCreated" , clineMessage : message } )
15661577 // Small delay to prevent overwhelming the webview
1567- await delay ( 10 )
1578+ await delay ( INCREMENTAL_SEND_DELAY_MS )
15681579 }
15691580 } else {
15701581 // Normal state update for new tasks or tasks without messages
You can’t perform that action at this time.
0 commit comments