Skip to content

Commit 9e79d9d

Browse files
authored
V3 backport #10734 (#10782)
* Improve error logging * Create spotty-knives-roll.md * fix lint * fix tests * fix tests * drop sentry
1 parent c9d567e commit 9e79d9d

File tree

16 files changed

+218
-162
lines changed

16 files changed

+218
-162
lines changed

.changeset/spotty-knives-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Improve formatting of logged errors in some cases

packages/wrangler/src/__tests__/cfetch-utils.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ describe("throwFetchError", () => {
147147
`[APIError: A request to the Cloudflare API (/user) failed.]`
148148
);
149149

150-
expect(std.out).toMatchInlineSnapshot(`
151-
"Getting User settings...
152-
153-
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/user) failed.[0m
150+
expect(std).toMatchInlineSnapshot(`
151+
Object {
152+
"debug": "",
153+
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/user) failed.[0m
154154
155155
error one [code: 10001]
156156
To learn more about this error, visit: https://example.com/1
@@ -169,7 +169,12 @@ describe("throwFetchError", () => {
169169
If you think this is a bug, please open an issue at:
170170
https://github.com/cloudflare/workers-sdk/issues/new/choose
171171
172-
"
172+
",
173+
"info": "",
174+
"out": "Getting User settings...
175+
",
176+
"warn": "",
177+
}
173178
`);
174179
});
175180

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -451,29 +451,24 @@ describe("deploy", () => {
451451
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/services/test-name) failed.]`
452452
);
453453
expect(std.out).toMatchInlineSnapshot(`
454-
"
455-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/services/test-name) failed.
456-
457-
Authentication error [code: 10000]
458-
459-
460-
📎 It looks like you are authenticating Wrangler via a custom API token set in an environment variable.
461-
Please ensure it has the correct permissions for this operation.
462-
463-
Getting User settings...
464-
ℹ️ The API Token is read from the CLOUDFLARE_API_TOKEN environment variable.
465-
👋 You are logged in with an User API Token, associated with the email [email protected].
466-
┌───────────────┬────────────┐
467-
│ Account Name │ Account ID │
468-
├───────────────┼────────────┤
469-
│ Account One │ account-1 │
470-
├───────────────┼────────────┤
471-
│ Account Two │ account-2 │
472-
├───────────────┼────────────┤
473-
│ Account Three │ account-3 │
474-
└───────────────┴────────────┘
475-
🔓 To see token permissions visit https://dash.cloudflare.com/profile/api-tokens."
476-
`);
454+
"
455+
📎 It looks like you are authenticating Wrangler via a custom API token set in an environment variable.
456+
Please ensure it has the correct permissions for this operation.
457+
458+
Getting User settings...
459+
ℹ️ The API Token is read from the CLOUDFLARE_API_TOKEN environment variable.
460+
👋 You are logged in with an User API Token, associated with the email [email protected].
461+
┌───────────────┬────────────┐
462+
│ Account Name │ Account ID │
463+
├───────────────┼────────────┤
464+
│ Account One │ account-1 │
465+
├───────────────┼────────────┤
466+
│ Account Two │ account-2 │
467+
├───────────────┼────────────┤
468+
│ Account Three │ account-3 │
469+
└───────────────┴────────────┘
470+
🔓 To see token permissions visit https://dash.cloudflare.com/profile/api-tokens."
471+
`);
477472
});
478473

479474
it("should error helpfully if pages_build_output_dir is set in wrangler.toml", async () => {
@@ -11552,19 +11547,18 @@ export default{
1155211547
expect(std).toMatchInlineSnapshot(`
1155311548
Object {
1155411549
"debug": "",
11555-
"err": "",
11556-
"info": "",
11557-
"out": "Total Upload: xx KiB / gzip: xx KiB
11558-
No bindings found.
11559-
11560-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.
11550+
"err": "X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.
1156111551
1156211552
Worker Startup Timed out. This could be due to script exceeding size limits or expensive code in
1156311553
the global scope. [code: 11337]
1156411554
1156511555
If you think this is a bug, please open an issue at:
1156611556
https://github.com/cloudflare/workers-sdk/issues/new/choose
1156711557
11558+
",
11559+
"info": "",
11560+
"out": "Total Upload: xx KiB / gzip: xx KiB
11561+
No bindings found.
1156811562
",
1156911563
"warn": "",
1157011564
}
@@ -11641,10 +11635,6 @@ export default{
1164111635
If these are unnecessary, consider removing them
1164211636
1164311637
11644-
",
11645-
"info": "",
11646-
"out": "Total Upload: xx KiB / gzip: xx KiB
11647-
No bindings found.
1164811638
1164911639
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.
1165011640
@@ -11653,6 +11643,10 @@ export default{
1165311643
If you think this is a bug, please open an issue at:
1165411644
https://github.com/cloudflare/workers-sdk/issues/new/choose
1165511645
11646+
",
11647+
"info": "",
11648+
"out": "Total Upload: xx KiB / gzip: xx KiB
11649+
No bindings found.
1165611650
",
1165711651
"warn": "",
1165811652
}
@@ -11717,10 +11711,6 @@ export default{
1171711711
.wrangler/tmp/startup-profile-<HASH>/worker.cpuprofile - load it into the Chrome DevTools profiler
1171811712
(or directly in VSCode) to view a flamegraph.
1171911713
11720-
",
11721-
"info": "",
11722-
"out": "Total Upload: xx KiB / gzip: xx KiB
11723-
No bindings found.
1172411714
1172511715
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.
1172611716
@@ -11729,6 +11719,10 @@ export default{
1172911719
If you think this is a bug, please open an issue at:
1173011720
https://github.com/cloudflare/workers-sdk/issues/new/choose
1173111721
11722+
",
11723+
"info": "",
11724+
"out": "Total Upload: xx KiB / gzip: xx KiB
11725+
No bindings found.
1173211726
",
1173311727
"warn": "",
1173411728
}

packages/wrangler/src/__tests__/pages/functions-build.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,14 @@ export default {
11421142
expect(buildMetadataExists).toBeFalsy();
11431143

11441144
// This logs a parsing error, but continues anyway
1145-
expect(std.err).toContain("ParseError");
1145+
expect(std.err).toMatchInlineSnapshot(`
1146+
"X [ERROR] Unexpected character, expected only whitespace or comments till end of line
1147+
1148+
<cwd>/wrangler.toml:5:23:
1149+
 5 │ limits = { cpu_ms = 50 }\\"
1150+
╵ ^
1151+
1152+
"
1153+
`);
11461154
});
11471155
});

packages/wrangler/src/__tests__/pages/pages-build-env.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,15 @@ describe("pages build env", () => {
120120
await runWrangler("pages functions build-env . --outfile data.json");
121121

122122
expect(process.exitCode).toEqual(EXIT_CODE_INVALID_PAGES_CONFIG);
123-
expect(std.err).toContain("ParseError");
123+
expect(std.err).toMatchInlineSnapshot(`
124+
"X [ERROR] Invalid character, expected \\"=\\"
125+
126+
<cwd>/wrangler.toml:1:8:
127+
 1 │ INVALID \\"FILE
128+
╵ ^
129+
130+
"
131+
`);
124132
expect(std.out).toMatchInlineSnapshot(`
125133
"Checking for configuration in a Wrangler configuration file (BETA)
126134

packages/wrangler/src/__tests__/pages/pages-download-config.test.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -863,18 +863,23 @@ describe("pages download config", () => {
863863
).rejects.toThrowErrorMatchingInlineSnapshot(
864864
`[APIError: A request to the Cloudflare API (/accounts/MOCK_ACCOUNT_ID/pages/projects/NOT_REAL) failed.]`
865865
);
866-
expect(std.out).toMatchInlineSnapshot(`
867-
"
868-
X [ERROR] A request to the Cloudflare API (/accounts/MOCK_ACCOUNT_ID/pages/projects/NOT_REAL) failed.
866+
expect(std).toMatchInlineSnapshot(`
867+
Object {
868+
"debug": "",
869+
"err": "X [ERROR] A request to the Cloudflare API (/accounts/MOCK_ACCOUNT_ID/pages/projects/NOT_REAL) failed.
869870
870-
Project not found. The specified project name does not match any of your existing projects. [code:
871-
8000007]
871+
Project not found. The specified project name does not match any of your existing projects. [code:
872+
8000007]
872873
873-
If you think this is a bug, please open an issue at:
874-
[4mhttps://github.com/cloudflare/workers-sdk/issues/new/choose[0m
874+
If you think this is a bug, please open an issue at:
875+
[4mhttps://github.com/cloudflare/workers-sdk/issues/new/choose[0m
875876
876-
"
877-
`);
877+
",
878+
"info": "",
879+
"out": "",
880+
"warn": "",
881+
}
882+
`);
878883
});
879884
describe("overwrite existing file", () => {
880885
it("should overwrite existing file w/ --force", async () => {

packages/wrangler/src/__tests__/pages/secret.test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -737,19 +737,24 @@ describe("wrangler pages secret", () => {
737737
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.]`
738738
);
739739

740-
expect(std.out).toMatchInlineSnapshot(`
741-
"🌀 Creating the secrets for the Worker \\"script-name\\"
742-
743-
🚨 Secrets failed to upload
744-
745-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.
740+
expect(std).toMatchInlineSnapshot(`
741+
Object {
742+
"debug": "",
743+
"err": "X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.
746744
747745
This is a helpful error [code: 1]
748746
749747
If you think this is a bug, please open an issue at:
750748
https://github.com/cloudflare/workers-sdk/issues/new/choose
751749
752-
"
750+
",
751+
"info": "",
752+
"out": "🌀 Creating the secrets for the Worker \\"script-name\\"
753+
754+
🚨 Secrets failed to upload
755+
",
756+
"warn": "",
757+
}
753758
`);
754759
});
755760
});

packages/wrangler/src/__tests__/pipelines.test.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -462,14 +462,19 @@ describe("pipelines", () => {
462462

463463
await endEventLoop();
464464

465-
expect(std.err).toMatchInlineSnapshot(`""`);
466-
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
467-
"Retrieving config for Pipeline \\"bad-pipeline\\".
468-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
465+
expect(std.err).toMatchInlineSnapshot(`
466+
"X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
467+
469468
Pipeline does not exist [code: 1000]
469+
470470
If you think this is a bug, please open an issue at:
471-
https://github.com/cloudflare/workers-sdk/issues/new/choose"
471+
https://github.com/cloudflare/workers-sdk/issues/new/choose
472+
473+
"
472474
`);
475+
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(
476+
`"Retrieving config for Pipeline \\"bad-pipeline\\"."`
477+
);
473478
expect(requests.count).toEqual(1);
474479
});
475480
});
@@ -592,13 +597,17 @@ describe("pipelines", () => {
592597

593598
await endEventLoop();
594599

595-
expect(std.err).toMatchInlineSnapshot(`""`);
596-
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
597-
"X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
600+
expect(std.err).toMatchInlineSnapshot(`
601+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.[0m
602+
598603
Pipeline does not exist [code: 1000]
604+
599605
If you think this is a bug, please open an issue at:
600-
https://github.com/cloudflare/workers-sdk/issues/new/choose"
606+
https://github.com/cloudflare/workers-sdk/issues/new/choose
607+
608+
"
601609
`);
610+
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`""`);
602611
expect(requests.count).toEqual(1);
603612
});
604613
});
@@ -627,14 +636,19 @@ describe("pipelines", () => {
627636

628637
await endEventLoop();
629638

630-
expect(std.err).toMatchInlineSnapshot(`""`);
631-
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
632-
"Deleting Pipeline bad-pipeline.
633-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
639+
expect(std.err).toMatchInlineSnapshot(`
640+
"X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
641+
634642
Pipeline does not exist [code: 1000]
643+
635644
If you think this is a bug, please open an issue at:
636-
https://github.com/cloudflare/workers-sdk/issues/new/choose"
645+
https://github.com/cloudflare/workers-sdk/issues/new/choose
646+
647+
"
637648
`);
649+
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(
650+
`"Deleting Pipeline bad-pipeline."`
651+
);
638652
expect(requests.count).toEqual(1);
639653
});
640654
});

packages/wrangler/src/__tests__/queues.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,10 @@ describe("wrangler", () => {
319319
runWrangler(`queues create ${queueName}`)
320320
).rejects.toThrowError();
321321
expect(std.out).toMatchInlineSnapshot(`
322-
"🌀 Creating queue 'testQueue'
323-
Queues is not currently enabled on this account. Go to https://dash.cloudflare.com/some-account-id/workers/queues to enable it.
324-
325-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/queues) failed.
326-
327-
workers.api.error.unauthorized [code: 10023]
328-
329-
If you think this is a bug, please open an issue at:
330-
https://github.com/cloudflare/workers-sdk/issues/new/choose
331-
332-
"
333-
`);
322+
"🌀 Creating queue 'testQueue'
323+
Queues is not currently enabled on this account. Go to https://dash.cloudflare.com/some-account-id/workers/queues to enable it.
324+
"
325+
`);
334326
});
335327

336328
it("should show an error when two delivery delays are set", async () => {

packages/wrangler/src/__tests__/r2.test.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -438,17 +438,22 @@ describe("r2", () => {
438438
).rejects.toThrowErrorMatchingInlineSnapshot(
439439
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.]`
440440
);
441-
expect(std.out).toMatchInlineSnapshot(`
442-
"Creating bucket 'test-bucket'...
443-
444-
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.[0m
441+
expect(std).toMatchInlineSnapshot(`
442+
Object {
443+
"debug": "",
444+
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.[0m
445445
446446
The JSON you provided was not well formed. [code: 10040]
447447
448448
If you think this is a bug, please open an issue at:
449449
https://github.com/cloudflare/workers-sdk/issues/new/choose
450450
451-
"
451+
",
452+
"info": "",
453+
"out": "Creating bucket 'test-bucket'...
454+
",
455+
"warn": "",
456+
}
452457
`);
453458
});
454459
});
@@ -524,17 +529,9 @@ describe("r2", () => {
524529
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/r2/buckets/testBucket) failed.]`
525530
);
526531
expect(std.out).toMatchInlineSnapshot(`
527-
"Updating bucket testBucket to Foo default storage class.
528-
529-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/r2/buckets/testBucket) failed.
530-
531-
The storage class specified is not valid. [code: 10062]
532-
533-
If you think this is a bug, please open an issue at:
534-
https://github.com/cloudflare/workers-sdk/issues/new/choose
535-
536-
"
537-
`);
532+
"Updating bucket testBucket to Foo default storage class.
533+
"
534+
`);
538535
});
539536

540537
it("should update the default storage class", async () => {

0 commit comments

Comments
 (0)