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
4 changes: 2 additions & 2 deletions packages/wrangler/e2e/secrets-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe.each(RUNTIMES)(
"🔐 Getting secret... (ID: 00000000000000000000000000000000)"
);
if (runtime === "remote") {
expect(normalize(output.stdout)).toContain(
expect(normalize(output.stderr)).toContain(
"secret_not_found [code: 1001]"
);
} else {
Expand Down Expand Up @@ -180,7 +180,7 @@ describe.each(RUNTIMES)(
expect(normalize(output.stdout)).toContain(
"🔐 Getting secret... (ID: 00000000000000000000000000000000)"
);
expect(normalize(output.stdout)).toContain(
expect(normalize(output.stderr)).toContain(
"store_not_found [code: 1001]"
);
});
Expand Down
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
36 changes: 20 additions & 16 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,16 @@ describe("deploy", () => {
).rejects.toThrowErrorMatchingInlineSnapshot(
`[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.
expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "X [ERROR] A request to the Cloudflare API (/accounts/some-account-id/workers/services/test-name) failed.

Authentication error [code: 10000]


",
"info": "",
"out": "
📎 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.

Expand All @@ -486,7 +489,9 @@ describe("deploy", () => {
├─┼─┤
│ Account Three │ account-3 │
└─┴─┘
🔓 To see token permissions visit https://dash.cloudflare.com/profile/api-tokens."
🔓 To see token permissions visit https://dash.cloudflare.com/profile/api-tokens.",
"warn": "",
}
`);
});

Expand Down Expand Up @@ -11381,18 +11386,17 @@ export default{
expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB

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
",
"warn": "",
}
Expand Down Expand Up @@ -11469,9 +11473,6 @@ export default{
If these are unnecessary, consider removing them


",
"info": "",
"out": "Total Upload: xx KiB / gzip: xx KiB

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

Expand All @@ -11480,6 +11481,9 @@ 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
",
"warn": "",
}
Expand Down Expand Up @@ -11544,9 +11548,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

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

Expand All @@ -11555,6 +11556,9 @@ 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
",
"warn": "",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,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,25 @@ 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": "▲ [WARNING] 🚧 \`wrangler pages download config\` is an experimental command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose

",
}
`);
});
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
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 @@ -448,17 +448,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 @@ -536,17 +541,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
25 changes: 15 additions & 10 deletions packages/wrangler/src/__tests__/secret.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,22 +1186,27 @@ describe("wrangler secret", () => {
`[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.]`
);

expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
🌀 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": "
⛅️ wrangler x.x.x
──────────────────
🌀 Creating the secrets for the Worker \\"script-name\\"

🚨 Secrets failed to upload
",
"warn": "",
}
`);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/api/startDevWorker/DevEnv.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "node:assert";
import { EventEmitter } from "node:events";
import { logger, runWithLogLevel } from "../../logger";
import { formatMessage, ParseError } from "../../parse";
import { ParseError } from "../../parse";
import { BundlerController } from "./BundlerController";
import { ConfigController } from "./ConfigController";
import { LocalRuntimeController } from "./LocalRuntimeController";
Expand Down Expand Up @@ -137,7 +137,7 @@ export class DevEnv extends EventEmitter {
ev.source === "ConfigController" &&
ev.cause instanceof ParseError
) {
logger.log(formatMessage(ev.cause));
logger.error(ev.cause);
}
// if other knowable + recoverable errors occur, handle them here
else {
Expand Down
Loading
Loading