fix(comfy): wrap malformed workflow json

This commit is contained in:
Vincent Koc
2026-05-15 08:32:11 +08:00
parent 62375ae860
commit 1d46a2f0b5
3 changed files with 36 additions and 1 deletions

View File

@@ -78,6 +78,7 @@ Docs: https://docs.openclaw.ai
- Telnyx voice-call: use the raw `client_state` fallback when webhook state is malformed base64 instead of using silently corrupted decoded text.
- Google Meet: report malformed node-host params JSON with plugin-owned errors instead of leaking raw JSON parser failures.
- CLI/export-trajectory: report malformed encoded request JSON with a stable CLI error instead of leaking raw parser output.
- ComfyUI: report malformed workflow API JSON responses with owned errors instead of leaking raw parser failures.
- Twilio voice-call: report malformed successful API JSON responses with provider-owned errors instead of leaking raw parser failures.
- Voice-call provider APIs: report malformed successful guarded JSON responses with provider-prefixed errors instead of leaking raw parser failures.
- Realtime transcription: report malformed provider websocket JSON frames with owned parser errors instead of leaking raw `SyntaxError` objects.

View File

@@ -201,6 +201,36 @@ describe("comfy image-generation provider", () => {
});
});
it("reports malformed local workflow submit JSON as a provider error", async () => {
_setComfyFetchGuardForTesting(fetchWithSsrFGuardMock);
const release = vi.fn(async () => {});
fetchWithSsrFGuardMock.mockResolvedValueOnce({
response: new Response("{ nope", {
status: 200,
headers: { "content-type": "application/json" },
}),
release,
});
const provider = buildComfyImageGenerationProvider();
await expect(
provider.generateImage({
provider: "comfy",
model: "workflow",
prompt: "draw a lobster",
cfg: buildComfyConfig({
workflow: {
"6": { inputs: { text: "" } },
"9": { inputs: {} },
},
promptNodeId: "6",
outputNodeId: "9",
}),
}),
).rejects.toThrow("Comfy workflow submit failed: malformed JSON response");
expect(release).toHaveBeenCalledTimes(1);
});
it("uploads reference images for local edit workflows", async () => {
_setComfyFetchGuardForTesting(fetchWithSsrFGuardMock);
fetchWithSsrFGuardMock

View File

@@ -299,7 +299,11 @@ async function readJsonResponse<T>(params: {
});
try {
await assertOkOrThrowHttpError(response, params.errorPrefix);
return (await response.json()) as T;
try {
return (await response.json()) as T;
} catch (cause) {
throw new Error(`${params.errorPrefix}: malformed JSON response`, { cause });
}
} finally {
await release();
}