Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wrangler] fix: throw helpful error if email validation required #4592

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Dec 12, 2023

Fixes #4187.

What this PR solves / how to test:

Previously, Wrangler would display the raw API error message and code if email validation was required during wrangler deploy. This change ensures a helpful error message is displayed instead, prompting users to check their emails or visit the dashboard for a verification link. To test this, try run wrangler deploy using a workers.dev subdomain on an account without a verified email. (I assume you've got one of those lying around! 😛)

Author has addressed the following:

  • Tests
    • Included
    • Not necessary because:
  • Changeset (Changeset guidelines)
    • Included
    • Not necessary because:
  • Associated docs
    • Issue(s)/PR(s):
    • Not necessary because: just changing the error message for existing behaviour

Note for PR author:

We want to celebrate and highlight awesome PR review! If you think this PR received a particularly high-caliber review, please assign it the label highlight pr review so future reviewers can take inspiration and learn from it.

@mrbbot mrbbot requested a review from a team as a code owner December 12, 2023 16:51
Copy link

changeset-bot bot commented Dec 12, 2023

🦋 Changeset detected

Latest commit: 62364fe

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mrbbot mrbbot changed the title fix: throw helpful error if email validation required [wrangler] fix: throw helpful error if email validation required Dec 12, 2023
Copy link
Contributor

github-actions bot commented Dec 12, 2023

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7387147635/npm-package-wrangler-4592

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7387147635/npm-package-wrangler-4592

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7387147635/npm-package-wrangler-4592 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7387147635/npm-package-miniflare-4592
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7387147635/npm-package-cloudflare-pages-shared-4592
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7387147635/npm-package-create-cloudflare-4592 --no-auto-update

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.22.1 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20231030.4
workerd 1.20231030.0 1.20231030.0
workerd --version 1.20231030.0 2023-10-30

|

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

Copy link

codecov bot commented Dec 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ba9b88f) 75.53% compared to head (62364fe) 75.21%.
Report is 37 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4592      +/-   ##
==========================================
- Coverage   75.53%   75.21%   -0.33%     
==========================================
  Files         242      243       +1     
  Lines       12918    13031     +113     
  Branches     3324     3348      +24     
==========================================
+ Hits         9758     9801      +43     
- Misses       3160     3230      +70     
Files Coverage Δ
packages/wrangler/src/cfetch/errors.ts 100.00% <100.00%> (ø)
packages/wrangler/src/cfetch/index.ts 90.47% <100.00%> (+0.18%) ⬆️

... and 20 files with indirect coverage changes

@dario-piotrowicz
Copy link
Member

dario-piotrowicz commented Dec 12, 2023

I don't think this fully fixes #4187

As I mentioned in #4187 (comment), I think that a significant part of the issue is that wrangler asks the user various different questions regarding what subdomain they want to use, but all those questions are a bit pointless since at the end the command is still going to fail if the email is not verified

So while having a more proper error message is an improvement I still think that the email should also be verified upfront before the rest of the questions.

Would that be possible?

Note

I can't remember for sure if the subdomain gets generated.... it might or might not 😅

@mrbbot mrbbot force-pushed the bcoll/helpful-email-validation-error branch from 83bace9 to 332b484 Compare December 12, 2023 17:33
await expect(
runWrangler("deploy ./index")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Please verify your account's email address and try again."`
Copy link
Contributor

@RamIdeas RamIdeas Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this snapshot contain the 2nd line? "Check your email for a verification link, or login to https://dash.cloudflare.com and request a new one."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional text is added as a "note" to the error. This error snapshot matcher only considers the "message" of the error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we care about the second line then I think we would need to catch the error and then stringify it before checking it against a snapshot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the assertion to check notes too. 👍

await expect(
runWrangler("deploy ./index")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Please verify your account's email address and try again."`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional text is added as a "note" to the error. This error snapshot matcher only considers the "message" of the error.

await expect(
runWrangler("deploy ./index")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Please verify your account's email address and try again."`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we care about the second line then I think we would need to catch the error and then stringify it before checking it against a snapshot.

}

export function maybeThrowFriendlyError(error: FetchError) {
if (error.message === "workers.api.error.email_verification_required") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that this helper will be expanded to handle converting other API errors into helpful errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly. Seemed likely there are more errors that could be friendlier.

@petebacondarwin
Copy link
Contributor

I don't think this fully fixes #4187

As I mentioned in #4187 (comment), I think that a significant part of the issue is that wrangler asks the user various different questions regarding what subdomain they want to use, but all those questions are a bit pointless since at the end the command is still going to fail if the email is not verified

So while having a more proper error message is an improvement I still think that the email should also be verified upfront before the rest of the questions.

Would that be possible?

Note

I can't remember for sure if the subdomain gets generated.... it might or might not 😅

Sadly, I think this is not really possible without changes to the backend that Wrangler talks to.

The order of requests is that we only get the email-verification error when we deploy to the subdomain, but we need to register the subdomain before we can deploy to it. So we need to ask the questions of the user before we can find out that they haven't validated their email.

I propose that we go ahead with this fix for now and decide whether we need to go further and change the flow somehow.

@petebacondarwin petebacondarwin added the error-messaging Improving user facing error messages label Dec 22, 2023
@mrbbot mrbbot force-pushed the bcoll/helpful-email-validation-error branch from 332b484 to 62364fe Compare January 2, 2024 14:52
@mrbbot mrbbot merged commit 20da658 into main Jan 2, 2024
17 checks passed
@mrbbot mrbbot deleted the bcoll/helpful-email-validation-error branch January 2, 2024 15:09
@workers-devprod workers-devprod mentioned this pull request Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-messaging Improving user facing error messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: wrangler should prompt to verify email if new users access before verification
4 participants