cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.58k stars 664 forks source link

🐛 BUG: wrangler secret:bulk command broke (again) when worker has DO bindings #5753

Open izidormaklary opened 4 months ago

izidormaklary commented 4 months ago

Which Cloudflare product(s) does this pertain to?

Wrangler core

What version(s) of the tool(s) are you using?

3.53.1[Wrangler]

What version of Node are you using?

20.10.0

What operating system and version are you using?

Mac Sonoma 14.1.1

Describe the Bug

Observed behavior

wrangler secret:bulk fails when trying to upload secrets to a worker with Durable Object binding. Not the first time it occurs: #4496. Although there is mention of the:

Failed to load .env file ".env.dev": Error: ENOENT: no such file or directory, open '.env.dev'

log line it seems irrelevant, but the response to the patch request (originally sanitized from the logs) saying:

{
      "code": 10061,
      "message": "Cannot create binding for class DurableObject that is not exported by the script"
}

indicates that the issue with durable objects and secret:bulk resurfaced.

It's important to note that it only occurs with existing workers, there is no issue when uploading secrets to a brand new worker

Expected behavior

It should upload secrets regardless of durable object bindings.

Steps to reproduce

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

--- 2024-05-03T12:38:19.820Z debug
🪵  Writing logs to " /User/root/.wrangler/logs/wrangler-2024-05-03_12-38-19_721.log"
---

--- 2024-05-03T12:38:19.820Z debug
Failed to load .env file ".env.dev": Error: ENOENT: no such file or directory, open '.env.dev'
    at Object.openSync (node:fs:581:18)
    at Object.readFileSync (node:fs:457:35)
    at tryLoadDotEnv (/User/root/node_modules/wrangler/wrangler-dist/cli.js:158790:72)
    at loadDotEnv (/User/root/node_modules/wrangler/wrangler-dist/cli.js:158801:12)
    at /User/root/node_modules/wrangler/wrangler-dist/cli.js:200143:20
    at /User/root/node_modules/wrangler/wrangler-dist/cli.js:165196:16
    at maybeAsyncResult (/User/root/node_modules/wrangler/wrangler-dist/cli.js:163417:44)
    at /User/root/node_modules/wrangler/wrangler-dist/cli.js:165195:14
    at /User/root/node_modules/wrangler/wrangler-dist/cli.js:163404:22
    at Array.reduce (<anonymous>) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '.env.dev'
}
---

--- 2024-05-03T12:38:19.821Z debug
Failed to load .env file ".env": Error: ENOENT: no such file or directory, open '.env'
    at Object.openSync (node:fs:581:18)
    at Object.readFileSync (node:fs:457:35)
    at tryLoadDotEnv (/User/root/node_modules/wrangler/wrangler-dist/cli.js:158790:72)
    at loadDotEnv (/User/root/node_modules/wrangler/wrangler-dist/cli.js:158801:50)
    at /User/root/node_modules/wrangler/wrangler-dist/cli.js:200143:20
    at /User/root/node_modules/wrangler/wrangler-dist/cli.js:165196:16
    at maybeAsyncResult (/User/root/node_modules/wrangler/wrangler-dist/cli.js:163417:44)
    at /User/root/node_modules/wrangler/wrangler-dist/cli.js:165195:14
    at /User/root/node_modules/wrangler/wrangler-dist/cli.js:163404:22
    at Array.reduce (<anonymous>) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '.env'
}
---

--- 2024-05-03T12:38:19.826Z log
 ⛅️ wrangler 3.53.1
-------------------
---

--- 2024-05-03T12:38:19.831Z log
🌀 Creating the secrets for the Worker "worker-name-dev" 
---

--- 2024-05-03T12:38:19.831Z debug
-- START CF API REQUEST: GET https://api.cloudflare.com/client/v4/accounts/{accountId}/workers/scripts/worker-name-dev/settings
---

--- 2024-05-03T12:38:19.831Z debug
HEADERS: {
  "User-Agent": "wrangler/3.53.1"
}
---

--- 2024-05-03T12:38:19.831Z debug
INIT: {}
---

--- 2024-05-03T12:38:19.831Z debug
-- END CF API REQUEST
---

--- 2024-05-03T12:38:20.778Z debug
-- START CF API RESPONSE: OK 200
---

--- 2024-05-03T12:38:20.779Z debug
HEADERS: {
 ...
}
---

--- 2024-05-03T12:38:20.779Z debug
RESPONSE: {
  "result": {
    "placement": {},
    "compatibility_date": "2024-04-05",
    "compatibility_flags": [
      "nodejs_compat"
    ],
    "usage_model": "standard",
    "tags": [],
    "tail_consumers": [],
    "logpush": true,
    "bindings": [
      {
        "class_name": "DurableObjectNamespace",
        "name": "DO",
        "namespace_id": "{do_id}",
        "script_name": "do-script-name-dev",
        "type": "durable_object_namespace"
      },
      {
        "name": "RANDOM_SECRET",
        "type": "secret_text"
      },
    ]
  },
  "success": true,
  "errors": [],
  "messages": []
}

---

--- 2024-05-03T12:38:20.779Z debug
-- END CF API RESPONSE
---

--- 2024-05-03T12:38:20.779Z debug
-- START CF API REQUEST: PATCH https://api.cloudflare.com/client/v4/accounts/{accountId}/workers/scripts/worker-name-dev/settings
---

--- 2024-05-03T12:38:20.779Z debug
HEADERS: {
  "User-Agent": "wrangler/3.53.1"
}
---

--- 2024-05-03T12:38:20.779Z debug
INIT: {
  "method": "PATCH",
  "body": {}
}
---

--- 2024-05-03T12:38:20.779Z debug
-- END CF API REQUEST
---

--- 2024-05-03T12:38:21.793Z debug
-- START CF API RESPONSE: Bad Request 400
---

--- 2024-05-03T12:38:21.794Z debug
HEADERS: {
  ...
}
---

--- 2024-05-03T12:38:21.794Z debug
RESPONSE: {
  "result": null,
  "success": false,
  "errors": [
    {
      "code": 10061,
      "message": "Cannot create binding for class DurableObject that is not exported by the script"
    }
  ],
  "messages": []
}

---

--- 2024-05-03T12:38:21.794Z debug
-- END CF API RESPONSE
---

--- 2024-05-03T12:38:21.794Z log

---

--- 2024-05-03T12:38:21.794Z log
Finished processing secrets JSON file:
---

--- 2024-05-03T12:38:21.794Z log
✨ 0 secrets successfully uploaded
---

--- 2024-05-03T12:38:21.795Z log

---

--- 2024-05-03T12:38:21.879Z error
✘ [ERROR] 🚨 9 secrets failed to upload

---

--- 2024-05-03T12:38:21.880Z log
If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose
---
izidormaklary commented 3 months ago

The bug is still there in v3.60.2 and its breaking our pipelines set up for multiple workers :(

penalosa commented 3 months ago

@matthewdavidrodgers could you have a look at this?

lrapoport-cf commented 3 weeks ago

i've connected with @matthewdavidrodgers on this -- there is some higher priority work on his plate at the moment, but this is on his radar to tackle as he becomes available, so assigning to him 👍