Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-lions-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/computer": patch
---

Embed the configured byte limit directly in Worker JavaScript capability size errors.
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ function isInternalModuleName(name: string) {
}

function capabilitiesModule(maxCapabilityBytes: number) {
const requestTooLargeMessage = `Workspace capability request exceeds ${maxCapabilityBytes} bytes.`;
return `
let host;
const callKey = Symbol.for("cloudflare.workspace.runtime.call");
Expand All @@ -258,7 +259,7 @@ function capabilitiesModule(maxCapabilityBytes: number) {
if (!host) throw new Error("Workspace capabilities are not installed");
const request = JSON.stringify(args.map(encode));
if (new TextEncoder().encode(request).byteLength > ${maxCapabilityBytes}) {
throw new Error("Workspace capability request exceeds ${maxCapabilityBytes} bytes.");
throw new Error(${JSON.stringify(requestTooLargeMessage)});
}
const raw = await host.call(namespace + "." + method, request);
const payload = JSON.parse(String(raw));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,39 @@ describe("WorkerJavaScriptBackend", () => {
).toThrow(/positive finite/);
});

it("includes the configured capability byte limit in generated errors", async () => {
const load = vi.fn(() => ({
getEntrypoint() {
return {
evaluate: (
_input: unknown,
host: {
assertResult(value: unknown): Promise<void>;
attachOutput(readable: ReadableStream<Uint8Array>): Promise<void>;
},
) => evaluateResult(host, null),
};
},
}));
const workspace = new Workspace({
storage: new SQLiteTestStorage(),
backends: [
new WorkerJavaScriptBackend({
loader: { load },
maxCapabilityBytes: 256,
}),
],
});
await workspace.fs.mkdir("/workspace", { recursive: true });

await (await workspace.runtime.exec("export default null")).result();

const capabilities = load.mock.calls[0]?.[0].modules["workspace-capabilities.js"];
expect(capabilities).toEqual(expect.any(String));
expect(capabilities).toContain("exceeds 256 bytes");
expect(capabilities).not.toContain("maxCapabilityBytes");
});

it("disposes Loader resources when evaluate throws synchronously", async () => {
let entrypointDisposals = 0;
let workerDisposals = 0;
Expand Down
Loading