Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spotty-knives-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Improve formatting of logged errors in some cases
15 changes: 10 additions & 5 deletions packages/wrangler/src/__tests__/cfetch-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ describe("throwFetchError", () => {
`[APIError: A request to the Cloudflare API (/user) failed.]`
);

expect(std.out).toMatchInlineSnapshot(`
"Getting User settings...

X [ERROR] A request to the Cloudflare API (/user) failed.
expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "X [ERROR] A request to the Cloudflare API (/user) failed.

error one [code: 10001]
To learn more about this error, visit: https://example.com/1
Expand All @@ -169,7 +169,12 @@ describe("throwFetchError", () => {
If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose

"
",
"info": "",
"out": "Getting User settings...
",
"warn": "",
}
`);
});

Expand Down
68 changes: 31 additions & 37 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,29 +451,24 @@ describe("deploy", () => {
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/services/test-name) failed.]`
);
expect(std.out).toMatchInlineSnapshot(`
"
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/services/test-name) failed.

Authentication error [code: 10000]


📎 It looks like you are authenticating Wrangler via a custom API token set in an environment variable.
Please ensure it has the correct permissions for this operation.

Getting User settings...
ℹ️ The API Token is read from the CLOUDFLARE_API_TOKEN environment variable.
👋 You are logged in with an User API Token, associated with the email user@example.com.
┌───────────────┬────────────┐
│ Account Name │ Account ID │
├───────────────┼────────────┤
│ Account One │ account-1 │
├───────────────┼────────────┤
│ Account Two │ account-2 │
├───────────────┼────────────┤
│ Account Three │ account-3 │
└───────────────┴────────────┘
🔓 To see token permissions visit https://dash.cloudflare.com/profile/api-tokens."
`);
"
📎 It looks like you are authenticating Wrangler via a custom API token set in an environment variable.
Please ensure it has the correct permissions for this operation.

Getting User settings...
ℹ️ The API Token is read from the CLOUDFLARE_API_TOKEN environment variable.
👋 You are logged in with an User API Token, associated with the email user@example.com.
┌───────────────┬────────────┐
│ Account Name │ Account ID │
├───────────────┼────────────┤
│ Account One │ account-1 │
├───────────────┼────────────┤
│ Account Two │ account-2 │
├───────────────┼────────────┤
│ Account Three │ account-3 │
└───────────────┴────────────┘
🔓 To see token permissions visit https://dash.cloudflare.com/profile/api-tokens."
`);
});

it("should error helpfully if pages_build_output_dir is set in wrangler.toml", async () => {
Expand Down Expand Up @@ -11555,19 +11550,18 @@ export default{
expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
No bindings found.

X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.
"err": "X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.

Worker Startup Timed out. This could be due to script exceeding size limits or expensive code in
the global scope. [code: 11337]

If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose

",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
No bindings found.
",
"warn": "",
}
Expand Down Expand Up @@ -11644,10 +11638,6 @@ export default{
If these are unnecessary, consider removing them


",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
No bindings found.

X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.

Expand All @@ -11656,6 +11646,10 @@ export default{
If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose

",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
No bindings found.
",
"warn": "",
}
Expand Down Expand Up @@ -11720,10 +11714,6 @@ export default{
.wrangler/tmp/startup-profile-<HASH>/worker.cpuprofile - load it into the Chrome DevTools profiler
(or directly in VSCode) to view a flamegraph.

",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
No bindings found.

X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/test-name/versions) failed.

Expand All @@ -11732,6 +11722,10 @@ export default{
If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose

",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
No bindings found.
",
"warn": "",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,14 @@ export default {
expect(buildMetadataExists).toBeFalsy();

// This logs a parsing error, but continues anyway
expect(std.err).toContain("ParseError");
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Unexpected character, expected only whitespace or comments till end of line

<cwd>/wrangler.toml:5:23:
 5 │ limits = { cpu_ms = 50 }\\"
╵ ^

"
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,15 @@ describe("pages build env", () => {
await runWrangler("pages functions build-env . --outfile data.json");

expect(process.exitCode).toEqual(EXIT_CODE_INVALID_PAGES_CONFIG);
expect(std.err).toContain("ParseError");
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Invalid character, expected \\"=\\"

<cwd>/wrangler.toml:1:8:
 1 │ INVALID \\"FILE
╵ ^

"
`);
expect(std.out).toMatchInlineSnapshot(`
"Checking for configuration in a Wrangler configuration file (BETA)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,18 +863,23 @@ describe("pages download config", () => {
).rejects.toThrowErrorMatchingInlineSnapshot(
`[APIError: A request to the Cloudflare API (/accounts/MOCK_ACCOUNT_ID/pages/projects/NOT_REAL) failed.]`
);
expect(std.out).toMatchInlineSnapshot(`
"
X [ERROR] A request to the Cloudflare API (/accounts/MOCK_ACCOUNT_ID/pages/projects/NOT_REAL) failed.
expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "X [ERROR] A request to the Cloudflare API (/accounts/MOCK_ACCOUNT_ID/pages/projects/NOT_REAL) failed.

Project not found. The specified project name does not match any of your existing projects. [code:
8000007]
Project not found. The specified project name does not match any of your existing projects. [code:
8000007]

If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose
If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose

"
`);
",
"info": "",
"out": "",
"warn": "",
}
`);
});
describe("overwrite existing file", () => {
it("should overwrite existing file w/ --force", async () => {
Expand Down
19 changes: 12 additions & 7 deletions packages/wrangler/src/__tests__/pages/secret.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,19 +737,24 @@ describe("wrangler pages secret", () => {
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.]`
);

expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating the secrets for the Worker \\"script-name\\"

🚨 Secrets failed to upload

X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.
expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.

This is a helpful error [code: 1]

If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose

"
",
"info": "",
"out": "🌀 Creating the secrets for the Worker \\"script-name\\"

🚨 Secrets failed to upload
",
"warn": "",
}
`);
});
});
Expand Down
42 changes: 28 additions & 14 deletions packages/wrangler/src/__tests__/pipelines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,19 @@ describe("pipelines", () => {

await endEventLoop();

expect(std.err).toMatchInlineSnapshot(`""`);
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
"Retrieving config for Pipeline \\"bad-pipeline\\".
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
Pipeline does not exist [code: 1000]
If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose"
https://github.com/cloudflare/workers-sdk/issues/new/choose
"
`);
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(
`"Retrieving config for Pipeline \\"bad-pipeline\\"."`
);
expect(requests.count).toEqual(1);
});
});
Expand Down Expand Up @@ -592,13 +597,17 @@ describe("pipelines", () => {

await endEventLoop();

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

await endEventLoop();

expect(std.err).toMatchInlineSnapshot(`""`);
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(`
"Deleting Pipeline bad-pipeline.
X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/pipelines/bad-pipeline) failed.
Pipeline does not exist [code: 1000]
If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose"
https://github.com/cloudflare/workers-sdk/issues/new/choose
"
`);
expect(normalizeOutput(std.out)).toMatchInlineSnapshot(
`"Deleting Pipeline bad-pipeline."`
);
expect(requests.count).toEqual(1);
});
});
Expand Down
16 changes: 4 additions & 12 deletions packages/wrangler/src/__tests__/queues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,10 @@ describe("wrangler", () => {
runWrangler(`queues create ${queueName}`)
).rejects.toThrowError();
expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating queue 'testQueue'
Queues is not currently enabled on this account. Go to https://dash.cloudflare.com/some-account-id/workers/queues to enable it.

X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/queues) failed.

workers.api.error.unauthorized [code: 10023]

If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose

"
`);
"🌀 Creating queue 'testQueue'
Queues is not currently enabled on this account. Go to https://dash.cloudflare.com/some-account-id/workers/queues to enable it.
"
`);
});

it("should show an error when two delivery delays are set", async () => {
Expand Down
29 changes: 13 additions & 16 deletions packages/wrangler/src/__tests__/r2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,22 @@ describe("r2", () => {
).rejects.toThrowErrorMatchingInlineSnapshot(
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.]`
);
expect(std.out).toMatchInlineSnapshot(`
"Creating bucket 'test-bucket'...

X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.
expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/r2/buckets) failed.

The JSON you provided was not well formed. [code: 10040]

If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose

"
",
"info": "",
"out": "Creating bucket 'test-bucket'...
",
"warn": "",
}
`);
});
});
Expand Down Expand Up @@ -524,17 +529,9 @@ describe("r2", () => {
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/r2/buckets/testBucket) failed.]`
);
expect(std.out).toMatchInlineSnapshot(`
"Updating bucket testBucket to Foo default storage class.

X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/r2/buckets/testBucket) failed.

The storage class specified is not valid. [code: 10062]

If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose

"
`);
"Updating bucket testBucket to Foo default storage class.
"
`);
});

it("should update the default storage class", async () => {
Expand Down
Loading
Loading