From bdb4b6e764473bb1dc3321d1d606afbeadaac66a Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 27 Nov 2025 16:38:05 +0100 Subject: [PATCH] fix: handle error messages that are not instanceof Error --- src/main.ts | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/main.ts b/src/main.ts index 8edd06cc..1b7111fd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -142,29 +142,22 @@ function registerTool(tool: ToolDefinition): void { response, context, ); - try { - const content = await response.handle(tool.name, context); - return { - content, - }; - } catch (error) { - logger(`${tool.name} response handling error:`, error, error.stack); - const errorText = - error instanceof Error ? error.message : String(error); - - return { - content: [ - { - type: 'text', - text: errorText, - }, - ], - isError: true, - }; - } + const content = await response.handle(tool.name, context); + return { + content, + }; } catch (err) { - logger(`${tool.name} error:`, err, err.stack); - throw err; + logger(`${tool.name} error:`, err, err?.stack); + const errorText = err && 'message' in err ? err.message : String(err); + return { + content: [ + { + type: 'text', + text: errorText, + }, + ], + isError: true, + }; } finally { guard.dispose(); }