Skip to content

Commit a67528a

Browse files
authored
fix: handle error messages that are not instanceof Error (#618)
Closes #617
1 parent bff5c65 commit a67528a

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/main.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,22 @@ function registerTool(tool: ToolDefinition): void {
142142
response,
143143
context,
144144
);
145-
try {
146-
const content = await response.handle(tool.name, context);
147-
return {
148-
content,
149-
};
150-
} catch (error) {
151-
logger(`${tool.name} response handling error:`, error, error.stack);
152-
const errorText =
153-
error instanceof Error ? error.message : String(error);
154-
155-
return {
156-
content: [
157-
{
158-
type: 'text',
159-
text: errorText,
160-
},
161-
],
162-
isError: true,
163-
};
164-
}
145+
const content = await response.handle(tool.name, context);
146+
return {
147+
content,
148+
};
165149
} catch (err) {
166-
logger(`${tool.name} error:`, err, err.stack);
167-
throw err;
150+
logger(`${tool.name} error:`, err, err?.stack);
151+
const errorText = err && 'message' in err ? err.message : String(err);
152+
return {
153+
content: [
154+
{
155+
type: 'text',
156+
text: errorText,
157+
},
158+
],
159+
isError: true,
160+
};
168161
} finally {
169162
guard.dispose();
170163
}

0 commit comments

Comments
 (0)