report friendly error when cli fails to find shops to display#3702
report friendly error when cli fails to find shops to display#3702sealocal wants to merge 1 commit intoShopify:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents hydrogen link (and other flows calling login) from crashing with “SelectPrompt requires at least one choice” by detecting when the authenticated account has zero shops to select and surfacing a friendly AbortError instead.
Changes:
- Add a guard in
login()to abort early whenuserAccount.activeShopsis empty, with a user-friendly message. - Add a unit test to ensure the empty-shops case throws and does not invoke
renderSelectPrompt.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/cli/src/lib/auth.ts | Adds an early AbortError when there are no shops to present to the select prompt. |
| packages/cli/src/lib/auth.test.ts | Adds coverage for the no-active-shops scenario and ensures the select prompt is not called. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if (!preselected && userAccount.activeShops.length === 0) { | ||
| throw new AbortError( | ||
| 'No shops found for your Shopify account.', |
There was a problem hiding this comment.
userAccount.activeShops is filtered to only status === 'ACTIVE' in getUserAccount, so the error headline could be misleading if the account has shops but none are active. Consider wording this as “No active shops found for your Shopify account.” (or similar) to match the actual condition being checked.
| 'No shops found for your Shopify account.', | |
| 'No active shops found for your Shopify account.', |
| shop && | ||
| userAccount.activeShops.find(({fqdn}) => shop === fqdn); | ||
|
|
||
| if (!preselected && userAccount.activeShops.length === 0) { |
There was a problem hiding this comment.
The !preselected && part of this condition is redundant because preselected can only be truthy when activeShops.length > 0. Simplifying to just if (userAccount.activeShops.length === 0) would make the intent clearer.
| if (!preselected && userAccount.activeShops.length === 0) { | |
| if (userAccount.activeShops.length === 0) { |
WHY are these changes introduced?
Fixes #2772 and #1463
The SelectPrompt component is being called and erroring out with 0 choices passed to it.
This approach avoids modifying the re-used SelectPrompt, isolating the change to one invocation of SelectPrompt.
WHAT is this pull request doing?
By checking for the condition before calling SelectPrompt, a friendly error message can be raised.
HOW to test your changes?
With a new user account that has no stores associated with it, attempt to link a store to a hydrogen project.
Before this change
After this change
Checklist