Skip to content

Commit

Permalink
Fix debug logging for Pages upload (#2884)
Browse files Browse the repository at this point in the history
* Switched console.debug for logger.debug

* changeset
  • Loading branch information
WalshyDev committed Mar 9, 2023
1 parent 6ebb23d commit e33bea9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-buses-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Changed console.debug for logger.debug in Pages uploading. This will ensure the debug logs are only sent when debug logging is enabled with `WRANGLER_LOG=debug`.
10 changes: 5 additions & 5 deletions packages/wrangler/src/pages/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const upload = async (
let attempts = 0;
const getMissingHashes = async (skipCaching: boolean): Promise<string[]> => {
if (skipCaching) {
console.debug("Force skipping cache");
logger.debug("Force skipping cache");
return files.map(({ hash }) => hash);
}

Expand Down Expand Up @@ -302,7 +302,7 @@ export const upload = async (
);

try {
console.debug("POST /pages/assets/upload");
logger.debug("POST /pages/assets/upload");
const res = await fetchResult(`/pages/assets/upload`, {
method: "POST",
headers: {
Expand All @@ -311,10 +311,10 @@ export const upload = async (
},
body: JSON.stringify(payload),
});
console.debug("result:", res);
logger.debug("result:", res);
} catch (e) {
if (attempts < MAX_UPLOAD_ATTEMPTS) {
console.debug("failed:", e, "retrying...");
logger.debug("failed:", e, "retrying...");
// Exponential backoff, 1 second first time, then 2 second, then 4 second etc.
await new Promise((resolvePromise) =>
setTimeout(resolvePromise, Math.pow(2, attempts++) * 1000)
Expand All @@ -326,7 +326,7 @@ export const upload = async (
}
return doUpload();
} else {
console.debug("failed:", e);
logger.debug("failed:", e);
throw e;
}
}
Expand Down

0 comments on commit e33bea9

Please sign in to comment.