fix(tools): keep tool errors concise

This commit is contained in:
Peter Steinberger
2026-01-07 19:04:04 +00:00
parent 579828b2d5
commit 43c7f5036a
4 changed files with 22 additions and 8 deletions

View File

@@ -28,6 +28,7 @@
- ClawdbotKit: fix SwiftPM resource bundling path for `tool-display.json`. Thanks @fcatuhe for PR #398.
- Tools: add Telegram/WhatsApp reaction tools (with per-provider gating). Thanks @zats for PR #353.
- Tools: flatten literal-union schemas for Claude on Vertex AI. Thanks @carlulsoe for PR #409.
- Tools: keep tool failure logs concise (no stack traces); full stack only in debug logs.
- Tools: unify reaction removal semantics across Discord/Slack/Telegram/WhatsApp and allow WhatsApp reaction routing across accounts.
- Android: fix APK output filename renaming after AGP updates. Thanks @Syhids for PR #410.
- Android: rotate camera photos by EXIF orientation. Thanks @fcatuhe for PR #403.

View File

@@ -1,6 +1,5 @@
import { describe, expect, it } from "vitest";
import type { AssistantMessage } from "@mariozechner/pi-ai";
import { describe, expect, it } from "vitest";
import {
buildBootstrapContextFiles,

View File

@@ -22,6 +22,7 @@ describe("pi tool definition adapter", () => {
status: "error",
tool: "boom",
});
expect(JSON.stringify(result.details)).toContain("nope");
expect(result.details).toMatchObject({ error: "nope" });
expect(JSON.stringify(result.details)).not.toContain("\n at ");
});
});

View File

@@ -4,12 +4,23 @@ import type {
AgentToolUpdateCallback,
} from "@mariozechner/pi-agent-core";
import type { ToolDefinition } from "@mariozechner/pi-coding-agent";
import { logError } from "../logger.js";
import { logDebug, logError } from "../logger.js";
import { jsonResult } from "./tools/common.js";
// biome-ignore lint/suspicious/noExplicitAny: TypeBox schema type from pi-agent-core uses a different module instance.
type AnyAgentTool = AgentTool<any, unknown>;
function describeToolExecutionError(err: unknown): {
message: string;
stack?: string;
} {
if (err instanceof Error) {
const message = err.message?.trim() ? err.message : String(err);
return { message, stack: err.stack };
}
return { message: String(err) };
}
export function toToolDefinitions(tools: AnyAgentTool[]): ToolDefinition[] {
return tools.map((tool) => {
const name = tool.name || "tool";
@@ -37,13 +48,15 @@ export function toToolDefinitions(tools: AnyAgentTool[]): ToolDefinition[] {
? String((err as { name?: unknown }).name)
: "";
if (name === "AbortError") throw err;
const message =
err instanceof Error ? (err.stack ?? err.message) : String(err);
logError(`[tools] ${tool.name} failed: ${message}`);
const described = describeToolExecutionError(err);
if (described.stack && described.stack !== described.message) {
logDebug(`tools: ${tool.name} failed stack:\n${described.stack}`);
}
logError(`[tools] ${tool.name} failed: ${described.message}`);
return jsonResult({
status: "error",
tool: tool.name,
error: message,
error: described.message,
});
}
},