Skip to content

[wrangler] Reject duplicate JSON config keys - #15764

Draft
yomna-shousha wants to merge 1 commit into
mainfrom
yomna/duplicate-wrangler-config-key-error
Draft

yomna-shousha wants to merge 1 commit into
mainfrom
yomna/duplicate-wrangler-config-key-error

Conversation

@yomna-shousha

Copy link
Copy Markdown
Contributor

What this changes

Rejects duplicate object keys when reading Wrangler JSON/JSONC configuration files.

This makes malformed config like two top-level previews blocks fail with a direct parse error instead of silently keeping the last value or surfacing an unrelated preview onboarding error.

Notes

I could not reproduce Scott's exact "missing previews block" error with two previews keys on Wrangler 4.136.1 locally. The duplicate-key config parsed as the last value and wrangler preview succeeded, which suggests the failing Workers Builds run may have used a cached config without previews. This still tightens the confusing malformed-config case Patrick called out.

Testing

  • pnpm --filter @cloudflare/workers-utils test run tests/parse.test.ts -t "duplicate object keys"
  • pnpm --filter wrangler test run src/__tests__/preview.test.ts -t "rejects duplicate previews blocks"
  • pnpm exec oxfmt --check packages/workers-utils/src/parse.ts packages/workers-utils/src/config/index.ts packages/workers-utils/tests/parse.test.ts packages/wrangler/src/__tests__/preview.test.ts

@changeset-bot

changeset-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b2dee07

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@cloudflare/workers-utils Patch
wrangler Patch
@cloudflare/autoconfig Patch
@cloudflare/cli-shared-helpers Patch
@cloudflare/containers-shared Patch
@cloudflare/deploy-helpers Patch
@cloudflare/remote-bindings Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-plugin Patch
@cloudflare/workers-auth Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ask-bonk

ask-bonk Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@pkg-pr-new

pkg-pr-new Bot commented Sep 21, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@15764

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@15764

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@15764

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@15764

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@15764

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@15764

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@15764

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@15764

miniflare

npm i https://pkg.pr.new/miniflare@15764

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@15764

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@15764

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@15764

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@15764

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@15764

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@15764

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@15764

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@15764

wrangler

npm i https://pkg.pr.new/wrangler@15764

commit: b2dee07

@petebacondarwin petebacondarwin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - ideally we could try to upstream this check to the jsonc library itself!

input: string,
file?: string,
options: jsoncParser.ParseOptions = { allowTrailingComma: true }
options: JSONCParseOptions = { allowTrailingComma: true }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's tweak this so that you don't need to provide the allowTrailingComma if you are just trying to add the dedup check...

Suggested change
options: JSONCParseOptions = { allowTrailingComma: true }
options: JSONCParseOptions = { }

and then further down:

options = { allowTrailingComma: true, ...options };

@github-project-automation github-project-automation Bot moved this from Untriaged to In Review in workers-sdk Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants