Skip to content

Commit 8926d51

Browse files
committed
Retain invalid materialization responses
1 parent 7d85c97 commit 8926d51

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

packages/runtime-playground/src/mount-materialization.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ function parseMaterializationJson<T extends { schema?: string }>(text: string, s
371371
try {
372372
parsed = JSON.parse(text || "{}")
373373
} catch (error) {
374-
throw new Error(`${command} returned invalid JSON: ${errorMessage(error)}`)
374+
const excerpt = text.trim().replace(/\s+/g, " ").slice(0, 500)
375+
throw new Error(`${command} returned invalid JSON: ${errorMessage(error)}${excerpt ? `; response excerpt: ${excerpt}` : ""}`)
375376
}
376377
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || (parsed as { schema?: unknown }).schema !== schema) {
377378
throw new Error(`${command} did not return ${schema}; received ${text.trim() || "empty response"}`)

tests/staged-input-materialization.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,24 @@ await withTempDir("wp-codebox-staged-input-materialization-binary-", async (root
115115
assert.ok(binaryWriteCode.includes(contents.toString("base64")), "the PHP materializer receives the exact base64 payload")
116116
})
117117

118+
await withTempDir("wp-codebox-staged-input-materialization-invalid-response-", async (root) => {
119+
const source = join(root, "image.bin")
120+
await writeFile(source, Buffer.from([0xff]))
121+
const server = {
122+
playground: {
123+
async run({ code }: { code: string }) {
124+
if (code.includes("wp-codebox/host-mount-materialization/v1")) {
125+
return { text: "<br />\n<b>Fatal error</b>: materialization failed" }
126+
}
127+
return { text: JSON.stringify({ schema: "wp-codebox/host-mount-directory-materialization/v1", created: 1, skipped: 0 }) }
128+
},
129+
},
130+
}
131+
132+
await assert.rejects(
133+
materializePlaygroundStagedInputs(server as never, [{ type: "file", source, target: "/wordpress/image.bin", mode: "readwrite" }]),
134+
/response excerpt: <br \/> <b>Fatal error<\/b>: materialization failed/,
135+
)
136+
})
137+
118138
console.log("staged input materialization ok")

0 commit comments

Comments
 (0)