Skip to content

Commit c5d013d

Browse files
Improve extract error formatting and warning output
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent e879b91 commit c5d013d

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/agent/actions/extract.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,16 @@ describe("ExtractActionDefinition.run", () => {
147147
expect(result.success).toBe(false);
148148
expect(result.message).toContain("No content extracted");
149149
});
150+
151+
it("returns formatted root error messages", async () => {
152+
parseMarkdown.mockRejectedValue(new Error("markdown parse failed"));
153+
const ctx = createContext();
154+
155+
const result = await ExtractActionDefinition.run(ctx, {
156+
objective: "Extract content",
157+
});
158+
159+
expect(result.success).toBe(false);
160+
expect(result.message).toContain("markdown parse failed");
161+
});
150162
});

src/agent/actions/extract.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ function writeDebugFileSafe(
7676
}
7777
}
7878

79+
function formatErrorMessage(error: unknown): string {
80+
return error instanceof Error ? error.message : String(error);
81+
}
82+
7983
export const ExtractActionDefinition: AgentActionDefinition = {
8084
type: "extract" as const,
8185
actionParams: ExtractAction,
@@ -101,7 +105,7 @@ export const ExtractActionDefinition: AgentActionDefinition = {
101105
if (ctx.debug) {
102106
console.warn(
103107
"[extract] Screenshot capture unavailable, falling back to markdown-only extraction:",
104-
error
108+
formatErrorMessage(error)
105109
);
106110
}
107111
}
@@ -172,7 +176,7 @@ export const ExtractActionDefinition: AgentActionDefinition = {
172176
} catch (error) {
173177
return {
174178
success: false,
175-
message: `Failed to extract content: ${error}`,
179+
message: `Failed to extract content: ${formatErrorMessage(error)}`,
176180
};
177181
}
178182
},

0 commit comments

Comments
 (0)