Skip to content

Commit 8d7f32e

Browse files
authored
Improve error logging (#10734)
* Improve error logging * Create spotty-knives-roll.md * fix secrets store e2e tests * inline error messages * fix lint
1 parent 76d2538 commit 8d7f32e

File tree

15 files changed

+174
-123
lines changed

15 files changed

+174
-123
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/e2e/secrets-store.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe.each(RUNTIMES)(
148148
"🔐 Getting secret... (ID: 00000000000000000000000000000000)"
149149
);
150150
if (runtime === "remote") {
151-
expect(normalize(output.stdout)).toContain(
151+
expect(normalize(output.stderr)).toContain(
152152
"secret_not_found [code: 1001]"
153153
);
154154
} else {
@@ -180,7 +180,7 @@ describe.each(RUNTIMES)(
180180
expect(normalize(output.stdout)).toContain(
181181
"🔐 Getting secret... (ID: 00000000000000000000000000000000)"
182182
);
183-
expect(normalize(output.stdout)).toContain(
183+
expect(normalize(output.stderr)).toContain(
184184
"store_not_found [code: 1001]"
185185
);
186186
});

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: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,16 @@ describe("deploy", () => {
464464
).rejects.toThrowErrorMatchingInlineSnapshot(
465465
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/services/test-name) failed.]`
466466
);
467-
expect(std.out).toMatchInlineSnapshot(`
468-
"
469-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/services/test-name) failed.
467+
expect(std).toMatchInlineSnapshot(`
468+
Object {
469+
"debug": "",
470+
"err": "X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/services/test-name) failed.
470471
471472
Authentication error [code: 10000]
472473
473-
474+
",
475+
"info": "",
476+
"out": "
474477
📎 It looks like you are authenticating Wrangler via a custom API token set in an environment variable.
475478
Please ensure it has the correct permissions for this operation.
476479
@@ -486,7 +489,9 @@ describe("deploy", () => {
486489
├─┼─┤
487490
│ Account Three │ account-3 │
488491
└─┴─┘
489-
🔓 To see token permissions visit https://dash.cloudflare.com/profile/api-tokens."
492+
🔓 To see token permissions visit https://dash.cloudflare.com/profile/api-tokens.",
493+
"warn": "",
494+
}
490495
`);
491496
});
492497

@@ -11381,18 +11386,17 @@ export default{
1138111386
expect(std).toMatchInlineSnapshot(`
1138211387
Object {
1138311388
"debug": "",
11384-
"err": "",
11385-
"info": "",
11386-
"out": "Total Upload: xx KiB / gzip: xx KiB
11387-
11388-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.
11389+
"err": "X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.
1138911390
1139011391
Worker Startup Timed out. This could be due to script exceeding size limits or expensive code in
1139111392
the global scope. [code: 11337]
1139211393
1139311394
If you think this is a bug, please open an issue at:
1139411395
https://github.com/cloudflare/workers-sdk/issues/new/choose
1139511396
11397+
",
11398+
"info": "",
11399+
"out": "Total Upload: xx KiB / gzip: xx KiB
1139611400
",
1139711401
"warn": "",
1139811402
}
@@ -11469,9 +11473,6 @@ export default{
1146911473
If these are unnecessary, consider removing them
1147011474
1147111475
11472-
",
11473-
"info": "",
11474-
"out": "Total Upload: xx KiB / gzip: xx KiB
1147511476
1147611477
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.
1147711478
@@ -11480,6 +11481,9 @@ export default{
1148011481
If you think this is a bug, please open an issue at:
1148111482
https://github.com/cloudflare/workers-sdk/issues/new/choose
1148211483
11484+
",
11485+
"info": "",
11486+
"out": "Total Upload: xx KiB / gzip: xx KiB
1148311487
",
1148411488
"warn": "",
1148511489
}
@@ -11544,9 +11548,6 @@ export default{
1154411548
.wrangler/tmp/startup-profile-<HASH>/worker.cpuprofile - load it into the Chrome DevTools profiler
1154511549
(or directly in VSCode) to view a flamegraph.
1154611550
11547-
",
11548-
"info": "",
11549-
"out": "Total Upload: xx KiB / gzip: xx KiB
1155011551
1155111552
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.
1155211553
@@ -11555,6 +11556,9 @@ export default{
1155511556
If you think this is a bug, please open an issue at:
1155611557
https://github.com/cloudflare/workers-sdk/issues/new/choose
1155711558
11559+
",
11560+
"info": "",
11561+
"out": "Total Upload: xx KiB / gzip: xx KiB
1155811562
",
1155911563
"warn": "",
1156011564
}

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

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

11741174
// This logs a parsing error, but continues anyway
1175-
expect(std.err).toContain("ParseError");
1175+
expect(std.err).toMatchInlineSnapshot(`
1176+
"X [ERROR] Unexpected character, expected only whitespace or comments till end of line
1177+
1178+
<cwd>/wrangler.toml:5:23:
1179+
 5 │ limits = { cpu_ms = 50 }\\"
1180+
╵ ^
1181+
1182+
"
1183+
`);
11761184
});
11771185
});

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: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -863,18 +863,25 @@ 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": "▲ [WARNING] 🚧 \`wrangler pages download config\` is an experimental command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
881+
882+
",
883+
}
884+
`);
878885
});
879886
describe("overwrite existing file", () => {
880887
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__/r2.test.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -448,17 +448,22 @@ describe("r2", () => {
448448
).rejects.toThrowErrorMatchingInlineSnapshot(
449449
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.]`
450450
);
451-
expect(std.out).toMatchInlineSnapshot(`
452-
"Creating bucket 'test-bucket'...
453-
454-
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.[0m
451+
expect(std).toMatchInlineSnapshot(`
452+
Object {
453+
"debug": "",
454+
"err": "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.[0m
455455
456456
The JSON you provided was not well formed. [code: 10040]
457457
458458
If you think this is a bug, please open an issue at:
459459
https://github.com/cloudflare/workers-sdk/issues/new/choose
460460
461-
"
461+
",
462+
"info": "",
463+
"out": "Creating bucket 'test-bucket'...
464+
",
465+
"warn": "",
466+
}
462467
`);
463468
});
464469
});
@@ -536,17 +541,9 @@ describe("r2", () => {
536541
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/r2/buckets/testBucket) failed.]`
537542
);
538543
expect(std.out).toMatchInlineSnapshot(`
539-
"Updating bucket testBucket to Foo default storage class.
540-
541-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/r2/buckets/testBucket) failed.
542-
543-
The storage class specified is not valid. [code: 10062]
544-
545-
If you think this is a bug, please open an issue at:
546-
https://github.com/cloudflare/workers-sdk/issues/new/choose
547-
548-
"
549-
`);
544+
"Updating bucket testBucket to Foo default storage class.
545+
"
546+
`);
550547
});
551548

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

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,22 +1186,27 @@ describe("wrangler secret", () => {
11861186
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.]`
11871187
);
11881188

1189-
expect(std.out).toMatchInlineSnapshot(`
1190-
"
1191-
⛅️ wrangler x.x.x
1192-
──────────────────
1193-
🌀 Creating the secrets for the Worker \\"script-name\\"
1194-
1195-
🚨 Secrets failed to upload
1196-
1197-
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.
1189+
expect(std).toMatchInlineSnapshot(`
1190+
Object {
1191+
"debug": "",
1192+
"err": "X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.
11981193
11991194
This is a helpful error [code: 1]
12001195
12011196
If you think this is a bug, please open an issue at:
12021197
https://github.com/cloudflare/workers-sdk/issues/new/choose
12031198
1204-
"
1199+
",
1200+
"info": "",
1201+
"out": "
1202+
⛅️ wrangler x.x.x
1203+
──────────────────
1204+
🌀 Creating the secrets for the Worker \\"script-name\\"
1205+
1206+
🚨 Secrets failed to upload
1207+
",
1208+
"warn": "",
1209+
}
12051210
`);
12061211
});
12071212

0 commit comments

Comments
 (0)