From f6f6259f23d844a72f79d93ca7d8fdb7f7bfb472 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Tue, 26 Nov 2024 01:55:42 -0800 Subject: [PATCH] fix error handling --- src/vs/platform/void/browser/llmMessageService.ts | 4 +++- .../void/electron-main/LLMMessageChannel.ts | 4 ++-- .../browser/react/src/sidebar-tsx/SidebarChat.tsx | 15 ++++++++------- .../void/browser/react/src/util/ErrorDisplay.tsx | 6 +++++- .../browser/react/src/util/sendLLMMessage.tsx | 6 +++--- .../contrib/void/browser/react/tsup.config.js | 2 +- .../contrib/void/browser/registerInlineDiffs.ts | 9 ++++++--- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/vs/platform/void/browser/llmMessageService.ts b/src/vs/platform/void/browser/llmMessageService.ts index 644c38ba..61f51ed8 100644 --- a/src/vs/platform/void/browser/llmMessageService.ts +++ b/src/vs/platform/void/browser/llmMessageService.ts @@ -19,7 +19,8 @@ export const ISendLLMMessageService = createDecorator('s // defines an interface that node/ creates and browser/ uses export interface ISendLLMMessageService { readonly _serviceBrand: undefined; - sendLLMMessage: (params: LLMMessageServiceParams) => void; + sendLLMMessage: (params: LLMMessageServiceParams) => string; + abort: (requestId: string) => void; } @@ -74,6 +75,7 @@ export class SendLLMMessageService implements ISendLLMMessageService { this._addDisposable(requestId_, onErrorEvent(e => { if (requestId_ !== e.requestId) return; + console.log('event onError', JSON.stringify(e)) onError(e) this._dispose(requestId_) }) diff --git a/src/vs/platform/void/electron-main/LLMMessageChannel.ts b/src/vs/platform/void/electron-main/LLMMessageChannel.ts index 82c747ac..9fb7224a 100644 --- a/src/vs/platform/void/electron-main/LLMMessageChannel.ts +++ b/src/vs/platform/void/electron-main/LLMMessageChannel.ts @@ -62,10 +62,11 @@ export class LLMMessageChannel implements IServerChannel { } } catch (e) { - console.log('sendLLM channel: call error', e) + console.log('llmMessageChannel: Call Error:', e) } } + // the only place sendLLMMessage is actually called private _callSendLLMMessage(params: ProxyLLMMessageParams) { const { requestId } = params; @@ -82,7 +83,6 @@ export class LLMMessageChannel implements IServerChannel { sendLLMMessage(mainThreadParams); } - private _callAbort(params: ProxyLLMMessageAbortParams) { const { requestId } = params; if (!(requestId in this._abortRefOfRequestId)) return diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index 5b62674c..fd36dfa4 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -175,7 +175,7 @@ export const SidebarChat = () => { // state of chat const [messageStream, setMessageStream] = useState('') const [isLoading, setIsLoading] = useState(false) - const abortFnRef = useRef<(() => void) | null>(null) + const latestRequestIdRef = useRef(null) const [latestError, setLatestError] = useState(null) @@ -225,7 +225,7 @@ export const SidebarChat = () => { setIsLoading(false) }, onError: ({ error }) => { - console.log('chat: running error') + console.log('chat: running error', error) // add assistant's message to chat history, and clear selection let content = messageStream; // just use the current content @@ -238,10 +238,10 @@ export const SidebarChat = () => { setLatestError(error) }, voidConfig, - abortRef: abortFnRef, } - sendLLMMessageService.sendLLMMessage(object) + const latestRequestId = sendLLMMessageService.sendLLMMessage(object) + latestRequestIdRef.current = latestRequestId setIsLoading(true) @@ -253,8 +253,9 @@ export const SidebarChat = () => { } const onAbort = () => { - // abort claude - abortFnRef.current?.() + // abort the LLM + if (latestRequestIdRef.current) + sendLLMMessageService.abort(latestRequestIdRef.current) // if messageStream was not empty, add it to the history const llmContent = messageStream || '(null)' @@ -342,7 +343,7 @@ export const SidebarChat = () => { {/* error message */} - {!latestError ? null : + {latestError === null ? null : { setLatestError(null) }} diff --git a/src/vs/workbench/contrib/void/browser/react/src/util/ErrorDisplay.tsx b/src/vs/workbench/contrib/void/browser/react/src/util/ErrorDisplay.tsx index 8ff04ebf..b51545c2 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/util/ErrorDisplay.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/util/ErrorDisplay.tsx @@ -28,9 +28,13 @@ const getErrorDetails = (error: unknown) => { e = new Error(String(error)) } + const message = e.message && e.error ? + (e.message + ':\n' + e.error) + : e.message || e.error || JSON.stringify(error) + details = { name: e.name || 'Error', - message: e.message || String(e), + message: message, stack: e.stack || null, cause: e.cause ? String(e.cause) : null, code: e.code || null, diff --git a/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx b/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx index e83d3c58..128ffd08 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx @@ -174,7 +174,7 @@ const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinal onError({ error: 'Invalid API key.' }); } else { - onError(error); + onError({ error }); } }) @@ -206,7 +206,7 @@ export const sendOllamaMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, }) // when error/fail .catch(error => { - onError(error) + onError({ error }) }) }; @@ -266,7 +266,7 @@ const sendGreptileMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFin }) .catch(error => { - onError(error) + onError({ error }) }); } diff --git a/src/vs/workbench/contrib/void/browser/react/tsup.config.js b/src/vs/workbench/contrib/void/browser/react/tsup.config.js index 31bdc100..a3432000 100644 --- a/src/vs/workbench/contrib/void/browser/react/tsup.config.js +++ b/src/vs/workbench/contrib/void/browser/react/tsup.config.js @@ -15,7 +15,7 @@ export default defineConfig({ // sourcemap: true, clean: true, - platform: 'browser', + platform: 'browser', // 'node' target: 'esnext', injectStyle: true, // bundle css into the output file outExtension: () => ({ js: '.js' }), diff --git a/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts b/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts index d5e3baa3..60894207 100644 --- a/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts +++ b/src/vs/workbench/contrib/void/browser/registerInlineDiffs.ts @@ -731,9 +731,10 @@ Please finish writing the new file by applying the diff to the original file. Re // ${suffix} // `; - const abortRef = { current: null } as { current: null | (() => void) } await new Promise((resolve, reject) => { + let streamRequestId: string | null = null + const object: LLMMessageServiceParams = { logging: { loggingName: 'streamChunk' }, messages: [ @@ -756,14 +757,16 @@ Please finish writing the new file by applying the diff to the original file. Re onError: (e: any) => { console.error('Error rewriting file with diff', e); // TODO indicate there was an error - abortRef.current?.() + if (streamRequestId) + this._sendLLMMessageService.abort(streamRequestId) + diffArea._sweepState = { isStreaming: false, line: null } resolve(); }, voidConfig, } - this._sendLLMMessageService.sendLLMMessage(object) + streamRequestId = this._sendLLMMessageService.sendLLMMessage(object) }) onFinishEdit()