惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
WordPress大学
WordPress大学
IT之家
IT之家
G
Google Developers Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler
V
V2EX
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
V
Visual Studio Blog
有赞技术团队
有赞技术团队
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(memory): wrap malformed remote json · openclaw/opencl...
vincentkoc · 2026-05-15 · via Recent Commits to openclaw:main

File tree

  • packages/memory-host-sdk/src/host

Original file line numberDiff line numberDiff line change

@@ -92,6 +92,7 @@ Docs: https://docs.openclaw.ai

9292

- Tavily: report malformed search and extract API JSON with provider-owned errors instead of leaking raw parser failures.

9393

- Perplexity: report malformed Search API and chat completion JSON with provider-owned errors instead of leaking raw parser failures.

9494

- Exa: report malformed search API JSON with a provider-owned error instead of leaking raw parser failures.

95+

- Memory host SDK: report malformed remote JSON with caller-scoped errors for POST and batch file upload responses instead of leaking raw parser failures.

9596

- Twilio voice-call: report malformed successful API JSON responses with provider-owned errors instead of leaking raw parser failures.

9697

- Voice-call provider APIs: report malformed successful guarded JSON responses with provider-prefixed errors instead of leaking raw parser failures.

9798

- Realtime transcription: report malformed provider websocket JSON frames with owned parser errors instead of leaking raw `SyntaxError` objects.

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,41 @@

1+

import { beforeEach, describe, expect, it, vi } from "vitest";

2+

import { uploadBatchJsonlFile } from "./batch-upload.js";

3+

import { withRemoteHttpResponse } from "./remote-http.js";

4+
5+

vi.mock("./remote-http.js", () => ({

6+

withRemoteHttpResponse: vi.fn(),

7+

}));

8+
9+

const remoteHttpMock = vi.mocked(withRemoteHttpResponse);

10+
11+

function textResponse(body: string, status: number): Response {

12+

return {

13+

ok: status >= 200 && status < 300,

14+

status,

15+

json: async () => JSON.parse(body) as unknown,

16+

text: async () => body,

17+

} as Response;

18+

}

19+
20+

describe("uploadBatchJsonlFile", () => {

21+

beforeEach(() => {

22+

vi.clearAllMocks();

23+

});

24+
25+

it("wraps malformed file-upload JSON with the request error prefix", async () => {

26+

remoteHttpMock.mockImplementationOnce(async (params) => {

27+

return await params.onResponse(textResponse("{ nope", 200));

28+

});

29+
30+

await expect(

31+

uploadBatchJsonlFile({

32+

client: {

33+

baseUrl: "https://memory.example/v1",

34+

headers: { Authorization: "Bearer test" },

35+

},

36+

requests: [{ input: "one" }],

37+

errorPrefix: "file upload failed",

38+

}),

39+

).rejects.toThrow("file upload failed: malformed JSON response");

40+

});

41+

});

Original file line numberDiff line numberDiff line change

@@ -34,7 +34,11 @@ export async function uploadBatchJsonlFile(params: {

3434

const text = await fileRes.text();

3535

throw new Error(`${params.errorPrefix}: ${fileRes.status} ${text}`);

3636

}

37-

return (await fileRes.json()) as { id?: string };

37+

try {

38+

return (await fileRes.json()) as { id?: string };

39+

} catch (cause) {

40+

throw new Error(`${params.errorPrefix}: malformed JSON response`, { cause });

41+

}

3842

},

3943

});

4044

if (!filePayload.id) {

Original file line numberDiff line numberDiff line change

@@ -70,4 +70,20 @@ describe("postJson", () => {

7070

expect((error as Error).message).toBe("post failed: 502 bad gateway");

7171

expect((error as { status?: unknown }).status).toBe(502);

7272

});

73+
74+

it("wraps malformed success JSON with the request error prefix", async () => {

75+

remoteHttpMock.mockImplementationOnce(async (params) => {

76+

return await params.onResponse(textResponse("{ nope", 200));

77+

});

78+
79+

await expect(

80+

postJson({

81+

url: "https://memory.example/v1/post",

82+

headers: {},

83+

body: {},

84+

errorPrefix: "post failed",

85+

parse: () => ({}),

86+

}),

87+

).rejects.toThrow("post failed: malformed JSON response");

88+

});

7389

});

Original file line numberDiff line numberDiff line change

@@ -31,7 +31,15 @@ export async function postJson<T>(params: {

3131

}

3232

throw err;

3333

}

34-

return await params.parse(await res.json());

34+

return await params.parse(await readJsonResponse(res, params.errorPrefix));

3535

},

3636

});

3737

}

38+
39+

async function readJsonResponse(res: Response, errorPrefix: string): Promise<unknown> {

40+

try {

41+

return await res.json();

42+

} catch (cause) {

43+

throw new Error(`${errorPrefix}: malformed JSON response`, { cause });

44+

}

45+

}