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
7 changes: 7 additions & 0 deletions .changeset/queues-consumers-not-array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/workers-utils": patch
---

Report an invalid `queues.consumers` value as a configuration error instead of crashing

Previously, setting `queues.consumers` to something other than an array (for example `null` or a string) could crash Wrangler or produce a flood of confusing extra errors. You now get a single clear message telling you the field must be an array.
14 changes: 7 additions & 7 deletions packages/workers-utils/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5114,13 +5114,13 @@ function validateQueues(envName: string): ValidatorFn {
)}.`
);
isValid = false;
}

for (let i = 0; i < consumers.length; i++) {
const consumer = consumers[i];
const consumerPath = `${fieldPath}.consumers[${i}]`;
if (!validateConsumer(diagnostics, consumerPath, consumer, config)) {
isValid = false;
} else {
for (let i = 0; i < consumers.length; i++) {
const consumer = consumers[i];
const consumerPath = `${fieldPath}.consumers[${i}]`;
if (!validateConsumer(diagnostics, consumerPath, consumer, config)) {
isValid = false;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4758,6 +4758,34 @@ describe("normalizeAndValidateConfig()", () => {
`);
});

it("should error if queues.consumers is null", ({ expect }) => {
const { diagnostics } = normalizeAndValidateConfig(
{ queues: { consumers: null } } as unknown as RawConfig,
undefined,
undefined,
{ env: undefined }
);

expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- The field "queues.consumers" should be an array but got null."
`);
});

it("should error once if queues.consumers is a string", ({ expect }) => {
const { diagnostics } = normalizeAndValidateConfig(
{ queues: { consumers: "my-queue" } } as unknown as RawConfig,
undefined,
undefined,
{ env: undefined }
);

expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- The field "queues.consumers" should be an array but got "my-queue"."
`);
});

it("should error if queues producer bindings are not valid", ({
expect,
}) => {
Expand Down
Loading