@@ -107,6 +107,31 @@ import type { ProjectFileContext } from '@codebuff/common/util/file'
107107
108108const LOW_BALANCE_THRESHOLD = 100
109109
110+ async function sendActionAndHandleError (
111+ ws : APIRealtimeClient ,
112+ action : ClientAction ,
113+ ) {
114+ try {
115+ return await ws . sendAction ( action )
116+ } catch ( e ) {
117+ // Print the error message for debugging.
118+ console . error (
119+ 'Error sending action:' ,
120+ action . type ,
121+ typeof e === 'object' && e !== null && 'message' in e ? e . message : e ,
122+ )
123+
124+ console . log ( )
125+ console . log ( 'Codebuff is exiting due to an error.' )
126+ console . log ( 'Make sure you are on the latest version of Codebuff!' )
127+ console . log ( '-----------------------------------' )
128+ console . log ( 'Please run: npm install -g codebuff' )
129+ console . log ( '-----------------------------------' )
130+
131+ process . exit ( 1 )
132+ }
133+ }
134+
110135const WARNING_CONFIG = {
111136 [ UserState . LOGGED_OUT ] : {
112137 message : ( ) => `Type "login" to unlock full access and get free credits!` ,
@@ -750,7 +775,7 @@ export class Client {
750775 const { filePaths, requestId } = a
751776 const files = getFiles ( filePaths )
752777
753- this . webSocket . sendAction ( {
778+ sendActionAndHandleError ( this . webSocket , {
754779 type : 'read-files-response' ,
755780 files,
756781 requestId,
@@ -778,7 +803,7 @@ export class Client {
778803 'User input ID mismatch - rejecting tool call request' ,
779804 )
780805
781- this . webSocket . sendAction ( {
806+ sendActionAndHandleError ( this . webSocket , {
782807 type : 'tool-call-response' ,
783808 requestId,
784809 success : false ,
@@ -804,7 +829,7 @@ export class Client {
804829 if ( this . userInputId ) {
805830 Spinner . get ( ) . start ( 'Processing results...' )
806831 }
807- this . webSocket . sendAction ( {
832+ sendActionAndHandleError ( this . webSocket , {
808833 type : 'tool-call-response' ,
809834 requestId,
810835 success : true ,
@@ -823,7 +848,7 @@ export class Client {
823848
824849 // Send error response back to backend
825850 Spinner . get ( ) . start ( 'Fixing...' )
826- this . webSocket . sendAction ( {
851+ sendActionAndHandleError ( this . webSocket , {
827852 type : 'tool-call-response' ,
828853 requestId,
829854 success : false ,
@@ -1032,7 +1057,7 @@ export class Client {
10321057 repoUrl : loggerContext . repoUrl ,
10331058 // repoName: loggerContext.repoName,
10341059 }
1035- this . webSocket . sendAction ( action )
1060+ sendActionAndHandleError ( this . webSocket , action )
10361061
10371062 return {
10381063 responsePromise,
@@ -1116,7 +1141,7 @@ export class Client {
11161141 ( id ) => id !== this . userInputId ,
11171142 )
11181143
1119- this . webSocket . sendAction ( {
1144+ sendActionAndHandleError ( this . webSocket , {
11201145 type : 'cancel-user-input' ,
11211146 authToken : this . user ?. authToken ,
11221147 promptId : this . userInputId ,
@@ -1554,7 +1579,7 @@ Go to https://www.codebuff.com/config for more information.`) +
15541579 // Add repoUrl here as per the diff for client.ts
15551580 repoUrl : loggerContext . repoUrl ,
15561581 }
1557- this . webSocket . sendAction ( initAction )
1582+ sendActionAndHandleError ( this . webSocket , initAction )
15581583
15591584 await this . fetchStoredApiKeyTypes ( )
15601585 }
0 commit comments