Skip to content

Commit 4b4d737

Browse files
committed
fix: handle BM error responses in schema-validate tool
When BM returns {error: 'No schema found...'}, the plugin crashed with 'Cannot read properties of undefined (reading length)' because it assumed the response always had results/valid_count/etc. Now checks for error responses first and returns them cleanly. Also guards against undefined results array.
1 parent ef11915 commit 4b4d737

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

tools/schema-validate.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ describe("schema-validate tool", () => {
117117
)
118118
})
119119

120+
it("should handle BM error response (no schema found)", async () => {
121+
;(
122+
mockClient.schemaValidate as jest.MockedFunction<any>
123+
).mockResolvedValue({
124+
error: "No schema found for type 'Task'",
125+
})
126+
127+
const result = await execute("call-1", { noteType: "Task" })
128+
129+
expect(result.content[0].text).toContain("No schema found")
130+
})
131+
120132
it("should handle errors gracefully", async () => {
121133
;(
122134
mockClient.schemaValidate as jest.MockedFunction<any>

tools/schema-validate.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,22 @@ export function registerSchemaValidateTool(
4848
params.project,
4949
)
5050

51+
// Handle error responses from BM (e.g., no schema found)
52+
if ("error" in result && typeof (result as any).error === "string") {
53+
return {
54+
content: [{ type: "text" as const, text: (result as any).error }],
55+
}
56+
}
57+
5158
const lines: string[] = []
5259
if (result.entity_type) {
5360
lines.push(`**Type:** ${result.entity_type}`)
5461
}
5562
lines.push(
56-
`**Notes:** ${result.total_notes} | **Valid:** ${result.valid_count} | **Warnings:** ${result.warning_count} | **Errors:** ${result.error_count}`,
63+
`**Notes:** ${result.total_notes ?? 0} | **Valid:** ${result.valid_count ?? 0} | **Warnings:** ${result.warning_count ?? 0} | **Errors:** ${result.error_count ?? 0}`,
5764
)
5865

59-
if (result.results.length > 0) {
66+
if (result.results && result.results.length > 0) {
6067
lines.push("")
6168
for (const r of result.results) {
6269
const status = r.valid ? "valid" : "invalid"

0 commit comments

Comments
 (0)