Skip to content

Commit 6940d39

Browse files
authored
more error telemetry (#10003)
1 parent cce7f6f commit 6940d39

File tree

6 files changed

+44
-16
lines changed

6 files changed

+44
-16
lines changed

.changeset/gold-shirts-wash.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Include more (sanitised) user errors in telemetry.
6+
7+
We manually vet and sanitised error messages before including them in our telemetry collection - this PR just includes a couple more.

packages/wrangler/src/assets.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ export function validateAssetsArgsAndConfig(
520520
) {
521521
throw new UserError(
522522
"Cannot use assets and Workers Sites in the same Worker.\n" +
523-
"Please remove either the `site` or `assets` field from your configuration file."
523+
"Please remove either the `site` or `assets` field from your configuration file.",
524+
{ telemetryMessage: true }
524525
);
525526
}
526527

packages/wrangler/src/deploy/deploy.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,15 @@ export default async function deploy(props: Props): Promise<{
395395
""
396396
).padStart(2, "0")}-${(new Date().getDate() + "").padStart(2, "0")}`;
397397

398-
throw new UserError(`A compatibility_date is required when publishing. Add the following to your ${configFileName(config.configPath)} file:
398+
throw new UserError(
399+
`A compatibility_date is required when publishing. Add the following to your ${configFileName(config.configPath)} file:
399400
\`\`\`
400401
${formatConfigSnippet({ compatibility_date: compatibilityDateStr }, config.configPath, false)}
401402
\`\`\`
402403
Or you could pass it in your terminal as \`--compatibility-date ${compatibilityDateStr}\`
403-
See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information.`);
404+
See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information.`,
405+
{ telemetryMessage: "missing compatibiltiy date when deploying" }
406+
);
404407
}
405408

406409
const routes =
@@ -482,25 +485,29 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
482485
format === "service-worker"
483486
) {
484487
throw new UserError(
485-
"You cannot use the service-worker format with an `assets` directory yet. For information on how to migrate to the module-worker format, see: https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/"
488+
"You cannot use the service-worker format with an `assets` directory yet. For information on how to migrate to the module-worker format, see: https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/",
489+
{ telemetryMessage: true }
486490
);
487491
}
488492

489493
if (config.wasm_modules && format === "modules") {
490494
throw new UserError(
491-
"You cannot configure [wasm_modules] with an ES module worker. Instead, import the .wasm module directly in your code"
495+
"You cannot configure [wasm_modules] with an ES module worker. Instead, import the .wasm module directly in your code",
496+
{ telemetryMessage: true }
492497
);
493498
}
494499

495500
if (config.text_blobs && format === "modules") {
496501
throw new UserError(
497-
`You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your ${configFileName(config.configPath)} file`
502+
`You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your ${configFileName(config.configPath)} file`,
503+
{ telemetryMessage: "[text_blobs] with an ES module worker" }
498504
);
499505
}
500506

501507
if (config.data_blobs && format === "modules") {
502508
throw new UserError(
503-
`You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your ${configFileName(config.configPath)} file`
509+
`You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your ${configFileName(config.configPath)} file`,
510+
{ telemetryMessage: "[data_blobs] with an ES module worker" }
504511
);
505512
}
506513

@@ -902,7 +909,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
902909
"binding DB of type d1 must have a valid `id` specified [code: 10021]"
903910
) {
904911
throw new UserError(
905-
"You must use a real database in the database_id configuration. You can find your databases using 'wrangler d1 list', or read how to develop locally with D1 here: https://developers.cloudflare.com/d1/configuration/local-development"
912+
"You must use a real database in the database_id configuration. You can find your databases using 'wrangler d1 list', or read how to develop locally with D1 here: https://developers.cloudflare.com/d1/configuration/local-development",
913+
{ telemetryMessage: true }
906914
);
907915
}
908916

@@ -1054,7 +1062,8 @@ async function publishRoutesFallback(
10541062
if (notProd) {
10551063
throw new UserError(
10561064
"Service environments combined with an API token that doesn't have 'All Zones' permissions is not supported.\n" +
1057-
"Either turn off service environments by setting `legacy_env = true`, creating an API token with 'All Zones' permissions, or logging in via OAuth"
1065+
"Either turn off service environments by setting `legacy_env = true`, creating an API token with 'All Zones' permissions, or logging in via OAuth",
1066+
{ telemetryMessage: true }
10581067
);
10591068
}
10601069
logger.warn(
@@ -1130,7 +1139,8 @@ async function publishRoutesFallback(
11301139
continue;
11311140
} else {
11321141
throw new UserError(
1133-
`The route with pattern "${routePattern}" is already associated with another worker called "${knownScript}".`
1142+
`The route with pattern "${routePattern}" is already associated with another worker called "${knownScript}".`,
1143+
{ telemetryMessage: "route already associated with another worker" }
11341144
);
11351145
}
11361146
}
@@ -1234,7 +1244,8 @@ export async function updateQueueConsumers(
12341244
if (scriptName === undefined) {
12351245
// TODO: how can we reliably get the current script name?
12361246
throw new UserError(
1237-
"Script name is required to update queue consumers"
1247+
"Script name is required to update queue consumers",
1248+
{ telemetryMessage: true }
12381249
);
12391250
}
12401251

packages/wrangler/src/deployment-bundle/entry.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export async function getEntry(
7777
if (config.pages_build_output_dir && command === "dev") {
7878
throw new UserError(
7979
"It looks like you've run a Workers-specific command in a Pages project.\n" +
80-
"For Pages, please run `wrangler pages dev` instead."
80+
"For Pages, please run `wrangler pages dev` instead.",
81+
{ telemetryMessage: true }
8182
);
8283
}
8384

@@ -151,7 +152,8 @@ export async function getEntry(
151152
const migrateUrl =
152153
"https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/";
153154
throw new UserError(
154-
`${errorMessage}\n${addScriptName}\n${addScriptNameExamples}\n${migrateText}\n${migrateUrl}`
155+
`${errorMessage}\n${addScriptName}\n${addScriptNameExamples}\n${migrateText}\n${migrateUrl}`,
156+
{ telemetryMessage: "tried to use DO with service worker" }
155157
);
156158
}
157159

packages/wrangler/src/dev.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,10 @@ export function getBindings(
10051005
// same copy-on-write TODO
10061006
if (!preview_bucket_name && !local) {
10071007
throw new UserError(
1008-
`In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your ${configFileName(configParam.configPath)} file`
1008+
`In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your ${configFileName(configParam.configPath)} file`,
1009+
{
1010+
telemetryMessage: "no preview r2 bucket configured in remote dev",
1011+
}
10091012
);
10101013
}
10111014
return {
@@ -1040,7 +1043,8 @@ export function getBindings(
10401043
hyperdrive.localConnectionString === undefined
10411044
) {
10421045
throw new UserError(
1043-
`When developing locally, you should use a local Postgres connection string to emulate Hyperdrive functionality. Please setup Postgres locally and set the value of the 'WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${hyperdrive.binding}' variable or "${hyperdrive.binding}"'s "localConnectionString" to the Postgres connection string.`
1046+
`When developing locally, you should use a local Postgres connection string to emulate Hyperdrive functionality. Please setup Postgres locally and set the value of the 'WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${hyperdrive.binding}' variable or "${hyperdrive.binding}"'s "localConnectionString" to the Postgres connection string.`,
1047+
{ telemetryMessage: "no local hyperdrive connection string" }
10441048
);
10451049
}
10461050

packages/wrangler/src/package-manager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ export async function getPackageManager(cwd: string): Promise<PackageManager> {
8888
return { ...PnpmPackageManager, cwd };
8989
} else {
9090
throw new UserError(
91-
"Unable to find a package manager. Supported managers are: npm, yarn, and pnpm."
91+
"Unable to find a package manager. Supported managers are: npm, yarn, and pnpm.",
92+
{
93+
telemetryMessage: true,
94+
}
9295
);
9396
}
9497
}

0 commit comments

Comments
 (0)