Skip to content

Commit c02b067

Browse files
authored
add more (sanitised) user errors to telemetry (#10000)
* more error telemetry * changeset and fixups
1 parent ad02ad3 commit c02b067

File tree

9 files changed

+65
-22
lines changed

9 files changed

+65
-22
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ export function getAssetsOptions(
475475
) {
476476
throw new UserError(
477477
"Cannot set run_worker_first without a Worker script.\n" +
478-
"Please remove run_worker_first from your configuration file, or provide a Worker script in your configuration file (`main`)."
478+
"Please remove run_worker_first from your configuration file, or provide a Worker script in your configuration file (`main`).",
479+
{ telemetryMessage: true }
479480
);
480481
}
481482

@@ -533,7 +534,8 @@ export function validateAssetsArgsAndConfig(
533534
) {
534535
throw new UserError(
535536
"Cannot use assets and Workers Sites in the same Worker.\n" +
536-
"Please remove either the `site` or `assets` field from your configuration file."
537+
"Please remove either the `site` or `assets` field from your configuration file.",
538+
{ telemetryMessage: true }
537539
);
538540
}
539541

packages/wrangler/src/deploy/deploy.ts

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

408-
throw new UserError(`A compatibility_date is required when publishing. Add the following to your ${configFileName(config.configPath)} file:
408+
throw new UserError(
409+
`A compatibility_date is required when publishing. Add the following to your ${configFileName(config.configPath)} file:
409410
\`\`\`
410411
${formatConfigSnippet({ compatibility_date: compatibilityDateStr }, config.configPath, false)}
411412
\`\`\`
412413
Or you could pass it in your terminal as \`--compatibility-date ${compatibilityDateStr}\`
413-
See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information.`);
414+
See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information.`,
415+
{ telemetryMessage: "missing compatibiltiy date when deploying" }
416+
);
414417
}
415418

416419
const routes =
@@ -495,25 +498,29 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
495498
format === "service-worker"
496499
) {
497500
throw new UserError(
498-
"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/"
501+
"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/",
502+
{ telemetryMessage: true }
499503
);
500504
}
501505

502506
if (config.wasm_modules && format === "modules") {
503507
throw new UserError(
504-
"You cannot configure [wasm_modules] with an ES module worker. Instead, import the .wasm module directly in your code"
508+
"You cannot configure [wasm_modules] with an ES module worker. Instead, import the .wasm module directly in your code",
509+
{ telemetryMessage: true }
505510
);
506511
}
507512

508513
if (config.text_blobs && format === "modules") {
509514
throw new UserError(
510-
`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`
515+
`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`,
516+
{ telemetryMessage: "[text_blobs] with an ES module worker" }
511517
);
512518
}
513519

514520
if (config.data_blobs && format === "modules") {
515521
throw new UserError(
516-
`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`
522+
`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`,
523+
{ telemetryMessage: "[data_blobs] with an ES module worker" }
517524
);
518525
}
519526

@@ -969,7 +976,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
969976
"binding DB of type d1 must have a valid `id` specified [code: 10021]"
970977
) {
971978
throw new UserError(
972-
"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"
979+
"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",
980+
{ telemetryMessage: true }
973981
);
974982
}
975983

@@ -1133,7 +1141,8 @@ async function publishRoutesFallback(
11331141
if (notProd) {
11341142
throw new UserError(
11351143
"Service environments combined with an API token that doesn't have 'All Zones' permissions is not supported.\n" +
1136-
"Either turn off service environments by setting `legacy_env = true`, creating an API token with 'All Zones' permissions, or logging in via OAuth"
1144+
"Either turn off service environments by setting `legacy_env = true`, creating an API token with 'All Zones' permissions, or logging in via OAuth",
1145+
{ telemetryMessage: true }
11371146
);
11381147
}
11391148
logger.warn(
@@ -1213,7 +1222,8 @@ async function publishRoutesFallback(
12131222
continue;
12141223
} else {
12151224
throw new UserError(
1216-
`The route with pattern "${routePattern}" is already associated with another worker called "${knownScript}".`
1225+
`The route with pattern "${routePattern}" is already associated with another worker called "${knownScript}".`,
1226+
{ telemetryMessage: "route already associated with another worker" }
12171227
);
12181228
}
12191229
}
@@ -1318,7 +1328,8 @@ export async function updateQueueConsumers(
13181328
if (scriptName === undefined) {
13191329
// TODO: how can we reliably get the current script name?
13201330
throw new UserError(
1321-
"Script name is required to update queue consumers"
1331+
"Script name is required to update queue consumers",
1332+
{ telemetryMessage: true }
13221333
);
13231334
}
13241335

packages/wrangler/src/deploy/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ export const deployCommand = createCommand({
227227
validateArgs(args) {
228228
if (args.nodeCompat) {
229229
throw new UserError(
230-
`The --node-compat flag is no longer supported as of Wrangler v4. Instead, use the \`nodejs_compat\` compatibility flag. This includes the functionality from legacy \`node_compat\` polyfills and natively implemented Node.js APIs. See https://developers.cloudflare.com/workers/runtime-apis/nodejs for more information.`
230+
`The --node-compat flag is no longer supported as of Wrangler v4. Instead, use the \`nodejs_compat\` compatibility flag. This includes the functionality from legacy \`node_compat\` polyfills and natively implemented Node.js APIs. See https://developers.cloudflare.com/workers/runtime-apis/nodejs for more information.`,
231+
{ telemetryMessage: true }
231232
);
232233
}
233234
},

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export async function getEntry(
7070
if (config.pages_build_output_dir && command === "dev") {
7171
throw new UserError(
7272
"It looks like you've run a Workers-specific command in a Pages project.\n" +
73-
"For Pages, please run `wrangler pages dev` instead."
73+
"For Pages, please run `wrangler pages dev` instead.",
74+
{ telemetryMessage: true }
7475
);
7576
}
7677

@@ -143,7 +144,8 @@ export async function getEntry(
143144
const migrateUrl =
144145
"https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/";
145146
throw new UserError(
146-
`${errorMessage}\n${addScriptName}\n${addScriptNameExamples}\n${migrateText}\n${migrateUrl}`
147+
`${errorMessage}\n${addScriptName}\n${addScriptNameExamples}\n${migrateText}\n${migrateUrl}`,
148+
{ telemetryMessage: "tried to use DO with service worker" }
147149
);
148150
}
149151

packages/wrangler/src/dev.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,11 @@ export function getBindings(
890890
// TODO: This error has to be a _lot_ better, ideally just asking
891891
// to create a preview namespace for the user automatically
892892
throw new UserError(
893-
`In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv namespace create <name> --preview" and add its id as preview_id to the kv_namespace "${binding}" in your ${configFileName(configParam.configPath)} file`
893+
`In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv namespace create <name> --preview" and add its id as preview_id to the kv_namespace "${binding}" in your ${configFileName(configParam.configPath)} file`,
894+
{
895+
telemetryMessage:
896+
"no preview kv namespace configured in remote dev",
897+
}
894898
); // Ugh, I really don't like this message very much
895899
}
896900
return {
@@ -946,7 +950,10 @@ export function getBindings(
946950
// same copy-on-write TODO
947951
if (!preview_bucket_name && !local) {
948952
throw new UserError(
949-
`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`
953+
`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`,
954+
{
955+
telemetryMessage: "no preview r2 bucket configured in remote dev",
956+
}
950957
);
951958
}
952959
return {
@@ -991,7 +998,8 @@ export function getBindings(
991998
hyperdrive.localConnectionString === undefined
992999
) {
9931000
throw new UserError(
994-
`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.`
1001+
`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.`,
1002+
{ telemetryMessage: "no local hyperdrive connection string" }
9951003
);
9961004
}
9971005

packages/wrangler/src/init.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ export const init = createCommand({
9999
} catch (err) {
100100
if ((err as { code?: number }).code === 10090) {
101101
throw new UserError(
102-
"wrangler couldn't find a Worker with that name in your account.\nRun `wrangler whoami` to confirm you're logged into the correct account."
102+
"wrangler couldn't find a Worker with that name in your account.\nRun `wrangler whoami` to confirm you're logged into the correct account.",
103+
{
104+
telemetryMessage: true,
105+
}
103106
);
104107
}
105108
throw err;

packages/wrangler/src/package-manager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export async function getPackageManager(): Promise<PackageManager> {
4040
return { ...PnpmPackageManager };
4141
} else {
4242
throw new UserError(
43-
"Unable to find a package manager. Supported managers are: npm, yarn, and pnpm."
43+
"Unable to find a package manager. Supported managers are: npm, yarn, and pnpm.",
44+
{
45+
telemetryMessage: true,
46+
}
4447
);
4548
}
4649
}

packages/wrangler/src/utils/print-bindings.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,18 @@ export function warnOrError(
777777
) {
778778
if (remote === true && supports === "local") {
779779
throw new UserError(
780-
`${friendlyBindingNames[type]} bindings do not support accessing remote resources.`
780+
`${friendlyBindingNames[type]} bindings do not support accessing remote resources.`,
781+
{
782+
telemetryMessage: true,
783+
}
781784
);
782785
}
783786
if (remote === false && supports === "remote") {
784787
throw new UserError(
785-
`${friendlyBindingNames[type]} bindings do not support local development. You may be able to set \`experimental_remote: true\` for the binding definition in your configuration file to access a remote version of the resource.`
788+
`${friendlyBindingNames[type]} bindings do not support local development. You may be able to set \`experimental_remote: true\` for the binding definition in your configuration file to access a remote version of the resource.`,
789+
{
790+
telemetryMessage: true,
791+
}
786792
);
787793
}
788794
if (remote === undefined && supports === "remote") {

0 commit comments

Comments
 (0)