Skip to content

🐛 BUG: Wrangler fails to validate R2 cors file properly and should error more helpfully #8486

@unknownterritory

Description

@unknownterritory

Which Cloudflare product(s) does this pertain to?

R2, Wrangler

What versions are you using?

4.0.0

What operating system and version are you using?

Linux POP!_OS 22.04 LTS

Please provide a link to a minimal reproduction

No response

Describe the Bug

  1. Create a bucket using wrangler r2 bucket create <your-bucket-name>
  2. Create a cors.json file with your policy.
  3. Set the CORS policy into the bucket with wrangler r2 bucket cors set test-bucket --file cors.json

The policy file contains the following:

{
	"rules": [
		{
			"AllowedOrigins": [
				"http://example.com"
			],
			"AllowedMethods": ["GET", "HEAD", "PUT", "POST", "DELETE"],
			"AllowedHeaders": [
				"Authorization",
				"Content-Type",
				"Cache-Control",
				"X-Requested-With"
			],
			"ExposeHeaders": [
				"ETag",
				"Content-Type",
				"Content-Length",
				"Content-Range"
			],
			"MaxAgeSeconds": 3600
		}
	]
}

I used the directive "rules" and not "CORSRules" by indication of wrangler that would throw an error about it otherwise.

The error also happened with the previous version of wrangler: 3.114.1

Please provide any relevant error logs

✘ [ERROR] A request to the Cloudflare API (/accounts/5dfb5fba4b0.../r2/buckets/test-bucket/cors) failed.

  The JSON you provided was not well formed. [code: 10040]

Metadata

Metadata

Assignees

Labels

bugSomething that isn't workingerror-messagingImproving user facing error messagesquick winPotentially easy/straightforward issue to tackler2Relating to R2

Type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions