Skip to content

Commit 3c5d273

Browse files
committed
fix: guard error handler against non-object thrown values
The `in` operator throws a TypeError when its right-hand operand is not an object. In the tool execution error handler, both `'message' in err` and `'cause' in err` will crash if the caught value is a primitive (null, string, number, undefined). Add `typeof err === 'object'` checks before using the `in` operator to ensure primitive thrown values are safely converted to strings.
1 parent 8d765c0 commit 3c5d273

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,11 @@ function registerTool(tool: ToolDefinition): void {
225225
return result;
226226
} catch (err) {
227227
logger(`${tool.name} error:`, err, err?.stack);
228-
let errorText = err && 'message' in err ? err.message : String(err);
229-
if ('cause' in err && err.cause) {
228+
let errorText =
229+
err && typeof err === 'object' && 'message' in err
230+
? err.message
231+
: String(err);
232+
if (err && typeof err === 'object' && 'cause' in err && err.cause) {
230233
errorText += `\nCause: ${err.cause.message}`;
231234
}
232235
return {

0 commit comments

Comments
 (0)