Skip to content

Commit cee82fa

Browse files
authored
chore: change some asserts to UserErrors so they don't get reported to sentry (#8048)
* assert -> error * telemetry messages
1 parent b1c8f67 commit cee82fa

File tree

9 files changed

+47
-25
lines changed

9 files changed

+47
-25
lines changed

packages/wrangler/src/deploy/index.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ async function deployWorker(args: DeployArgs) {
272272
if (config.pages_build_output_dir) {
273273
throw new UserError(
274274
"It looks like you've run a Workers-specific command in a Pages project.\n" +
275-
"For Pages, please run `wrangler pages deploy` instead."
275+
"For Pages, please run `wrangler pages deploy` instead.",
276+
{ telemetryMessage: true }
276277
);
277278
}
278279
// We use the `userConfigPath` to compute the root of a project,
@@ -284,12 +285,14 @@ async function deployWorker(args: DeployArgs) {
284285

285286
if (args.public) {
286287
throw new UserError(
287-
"The --public field has been deprecated, try --legacy-assets instead."
288+
"The --public field has been deprecated, try --legacy-assets instead.",
289+
{ telemetryMessage: true }
288290
);
289291
}
290292
if (args.experimentalPublic) {
291293
throw new UserError(
292-
"The --experimental-public field has been deprecated, try --legacy-assets instead."
294+
"The --experimental-public field has been deprecated, try --legacy-assets instead.",
295+
{ telemetryMessage: true }
293296
);
294297
}
295298

@@ -298,7 +301,8 @@ async function deployWorker(args: DeployArgs) {
298301
(args.site || config.site)
299302
) {
300303
throw new UserError(
301-
"Cannot use legacy assets and Workers Sites in the same Worker."
304+
"Cannot use legacy assets and Workers Sites in the same Worker.",
305+
{ telemetryMessage: true }
302306
);
303307
}
304308

@@ -349,10 +353,12 @@ async function deployWorker(args: DeployArgs) {
349353
workerNameOverridden = true;
350354
}
351355

352-
assert(
353-
name,
354-
'You need to provide a name when publishing a worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`'
355-
);
356+
if (!name) {
357+
throw new UserError(
358+
'You need to provide a name when publishing a worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`',
359+
{ telemetryMessage: true }
360+
);
361+
}
356362

357363
if (!args.dryRun) {
358364
assert(accountId, "Missing account ID");

packages/wrangler/src/triggers/deploy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export default async function triggersDeploy(
5555

5656
if (!scriptName) {
5757
throw new UserError(
58-
'You need to provide a name when uploading a Worker Version. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`'
58+
'You need to provide a name when uploading a Worker Version. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`',
59+
{ telemetryMessage: true }
5960
);
6061
}
6162

@@ -86,7 +87,7 @@ export default async function triggersDeploy(
8687
}
8788

8889
if (!accountId) {
89-
throw new UserError("Missing accountId");
90+
throw new UserError("Missing accountId", { telemetryMessage: true });
9091
}
9192

9293
const uploadMs = Date.now() - start;

packages/wrangler/src/versions/deploy.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export const versionsDeployCommand = createCommand({
114114

115115
if (workerName === undefined) {
116116
throw new UserError(
117-
'You need to provide a name of your worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`'
117+
'You need to provide a name of your worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`',
118+
{ telemetryMessage: true }
118119
);
119120
}
120121

@@ -144,13 +145,16 @@ export const versionsDeployCommand = createCommand({
144145

145146
// validate we have at least 1 version
146147
if (confirmedVersionsToDeploy.length === 0) {
147-
throw new UserError("You must select at least 1 version to deploy.");
148+
throw new UserError("You must select at least 1 version to deploy.", {
149+
telemetryMessage: true,
150+
});
148151
}
149152

150153
// validate we have at most experimentalMaxVersions (default: 2)
151154
if (confirmedVersionsToDeploy.length > args.maxVersions) {
152155
throw new UserError(
153-
`You must select at most ${args.maxVersions} versions to deploy.`
156+
`You must select at most ${args.maxVersions} versions to deploy.`,
157+
{ telemetryMessage: "You must select at most 2 versions to deploy.`" }
154158
);
155159
}
156160

packages/wrangler/src/versions/deployments/list.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export const deploymentsListCommand = createCommand({
4747

4848
if (workerName === undefined) {
4949
throw new UserError(
50-
'You need to provide a name for your Worker. Either pass it as a cli arg with `--name <name>` or in your configuration file as `name = "<name>"`'
50+
'You need to provide a name for your Worker. Either pass it as a cli arg with `--name <name>` or in your configuration file as `name = "<name>"`',
51+
{ telemetryMessage: true }
5152
);
5253
}
5354

packages/wrangler/src/versions/deployments/status.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ export const deploymentsStatusCommand = createCommand({
5252

5353
if (workerName === undefined) {
5454
throw new UserError(
55-
'You need to provide a name for your Worker. Either pass it as a cli arg with `--name <name>` or in your configuration file as `name = "<name>"`'
55+
'You need to provide a name for your Worker. Either pass it as a cli arg with `--name <name>` or in your configuration file as `name = "<name>"`',
56+
{ telemetryMessage: true }
5657
);
5758
}
5859

5960
const latestDeployment = await fetchLatestDeployment(accountId, workerName);
6061

6162
if (!latestDeployment) {
62-
throw new UserError(`The Worker ${workerName} has no deployments.`);
63+
throw new UserError(`The Worker ${workerName} has no deployments.`, {
64+
telemetryMessage: "The Worker has no deployments",
65+
});
6366
}
6467

6568
if (args.json) {

packages/wrangler/src/versions/list.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export const versionsListCommand = createCommand({
4444

4545
if (workerName === undefined) {
4646
throw new UserError(
47-
'You need to provide a name of your worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`'
47+
'You need to provide a name of your worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`',
48+
{ telemetryMessage: true }
4849
);
4950
}
5051

packages/wrangler/src/versions/rollback/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export const versionsRollbackCommand = createCommand({
4848

4949
if (workerName === undefined) {
5050
throw new UserError(
51-
'You need to provide a name for your Worker. Either pass it as a cli arg with `--name <name>` or in your configuration file as `name = "<name>"`'
51+
'You need to provide a name for your Worker. Either pass it as a cli arg with `--name <name>` or in your configuration file as `name = "<name>"`',
52+
{ telemetryMessage: true }
5253
);
5354
}
5455

packages/wrangler/src/versions/upload.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,14 @@ export const versionsUploadCommand = createCommand({
314314

315315
if (args.site || config.site) {
316316
throw new UserError(
317-
"Workers Sites does not support uploading versions through `wrangler versions upload`. You must use `wrangler deploy` instead."
317+
"Workers Sites does not support uploading versions through `wrangler versions upload`. You must use `wrangler deploy` instead.",
318+
{ telemetryMessage: true }
318319
);
319320
}
320321
if (args.legacyAssets || config.legacy_assets) {
321322
throw new UserError(
322-
"Legacy assets does not support uploading versions through `wrangler versions upload`. You must use `wrangler deploy` instead."
323+
"Legacy assets does not support uploading versions through `wrangler versions upload`. You must use `wrangler deploy` instead.",
324+
{ telemetryMessage: true }
323325
);
324326
}
325327

@@ -365,10 +367,12 @@ export const versionsUploadCommand = createCommand({
365367
workerNameOverridden = true;
366368
}
367369

368-
assert(
369-
name,
370-
'You need to provide a name when publishing a worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`'
371-
);
370+
if (!name) {
371+
throw new UserError(
372+
'You need to provide a name of your worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`',
373+
{ telemetryMessage: true }
374+
);
375+
}
372376

373377
if (!args.dryRun) {
374378
assert(accountId, "Missing account ID");

packages/wrangler/src/versions/view.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export const versionsViewCommand = createCommand({
5252

5353
if (workerName === undefined) {
5454
throw new UserError(
55-
'You need to provide a name of your worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`'
55+
'You need to provide a name of your worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`',
56+
{ telemetryMessage: true }
5657
);
5758
}
5859

0 commit comments

Comments
 (0)