workers-sdk
workers-sdk copied to clipboard
🐛 BUG: script reload duplicates all previous `console.log`s and uncaught errors
What version of Wrangler are you using?
2.0.29
What operating system are you using?
Mac
Describe the Bug
After uploading a new script on file change, Wrangler will re-log all previously logged messages and uncaught errors. It's possible this is intended behaviour, but to me it's a little confusing, as it makes it seem like old versions of the script are still running. Notably, the duplicated error stack traces will still use the most up-to-date source maps, leading to incorrect source location reporting.
Example
export default {
async fetch(request) {
const { pathname } = new URL(request.url);
if (pathname === "/") {
console.log("message1");
return new Response();
} else {
return new Response(null, { status: 404 });
}
},
};
$ wrangler2 dev issue.js
⛅️ wrangler 2.0.29
--------------------
Retrieving cached values for userId from node_modules/.cache/wrangler
⬣ Listening at http://0.0.0.0:8787
Total Upload: 0.35 KiB / gzip: 0.23 KiB
13:01:00 GET / 200
message1 # 1) Visit http://localhost:8787 in browser
13:01:00 GET /favicon.ico 404
⎔ Detected changes, restarted server. # 2) Update `message1` to `message2`
Total Upload: 0.35 KiB / gzip: 0.23 KiB
message1 # 3) Unexpected, `message1` from previous request logged
Script modified; context reset.
message2 # 4) Visit http://localhost:8787 in browser
13:01:08 GET / 200
⎔ Detected changes, restarted server. # 5) Update `message2` to `message3`
Total Upload: 0.35 KiB / gzip: 0.23 KiB
message1 # 6) Unexpected, `message1` and `message2` from previous
message2 # requests logged
Script modified; context reset.
message3 # 7) Visit http://localhost:8787 in browser
13:01:16 GET / 200
For an example with uncaught errors:
export default {
async fetch(request) {
const { pathname } = new URL(request.url);
if (pathname === "/") {
throw new Error("message1");
} else {
return new Response(null, { status: 404 });
}
},
};
Following the same steps as above gives:
$ wrangler2 dev issue.js
⛅️ wrangler 2.0.29
--------------------
Retrieving cached values for userId from node_modules/.cache/wrangler
⬣ Listening at http://0.0.0.0:8787
Total Upload: 0.33 KiB / gzip: 0.23 KiB
# 1) Visit http://localhost:8787 in browser
13:12:15 GET / 500
✘ [ERROR] Uncaught (in promise) Error: message1
throw new Error("message1");
^
at fetch (/Users/mrbbot/Desktop/wrangler-playground/ws-issues.js:5:12)
✘ [ERROR] Uncaught (in response) Error: message1
13:12:15 GET /cdn-cgi/styles/cf.errors.css 304
13:12:15 GET /favicon.ico 404
# 2) Update `message1` to `message2`
⎔ Detected changes, restarted server.
Total Upload: 0.33 KiB / gzip: 0.23 KiB
# 3) Unexpected, `message1` error from previous request logged
✘ [ERROR] Uncaught (in response) Error: message1
✘ [ERROR] Uncaught (in promise) Error: message1
throw new Error("message2"); # Note incorrect source mapping here too
^
at fetch (/Users/mrbbot/Desktop/wrangler-playground/ws-issues.js:5:12)
Script modified; context reset.
# 4) Visit http://localhost:8787 in browser
13:12:28 GET / 500
✘ [ERROR] Uncaught (in promise) Error: message2
throw new Error("message2");
^
at fetch (/Users/mrbbot/Desktop/wrangler-playground/ws-issues.js:5:12)
✘ [ERROR] Uncaught (in response) Error: message2
# 5) Update `message2` to `message3`
⎔ Detected changes, restarted server.
Total Upload: 0.33 KiB / gzip: 0.23 KiB
# 6a) Unexpected, `message1` error from previous request logged
✘ [ERROR] Uncaught Error: message1
throw new Error("message3"); # Note incorrect source mapping here too
^
at fetch (/Users/mrbbot/Desktop/wrangler-playground/ws-issues.js:5:12)
✘ [ERROR] Uncaught Error: message1
# 6b) Unexpected, `message2` error from previous request logged
✘ [ERROR] Uncaught (in promise) Error: message2
throw new Error("message3"); # Note incorrect source mapping here too
^
at fetch (/Users/mrbbot/Desktop/wrangler-playground/ws-issues.js:5:12)
✘ [ERROR] Uncaught (in response) Error: message2
Script modified; context reset.
# 7) Visit http://localhost:8787 in browser
✘ [ERROR] Uncaught (in promise) Error: message3
throw new Error("message3");
^
at fetch (/Users/mrbbot/Desktop/wrangler-playground/ws-issues.js:5:12)
✘ [ERROR] Uncaught (in response) Error: message3
13:12:38 GET / 500