-
Notifications
You must be signed in to change notification settings - Fork 228
On app selecetion keep retrying when failing but avoid capturing unrelated errors #6904
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import {getCachedCommandInfo, setCachedCommandTomlPreference} from '../local-sto | |
| import {CreateAppOptions, DeveloperPlatformClient} from '../../utilities/developer-platform-client.js' | ||
| import {AppConfigurationFileName} from '../../models/app/loader.js' | ||
| import {BugError} from '@shopify/cli-kit/node/error' | ||
| import {outputInfo, outputDebug} from '@shopify/cli-kit/node/output' | ||
| import {outputInfo} from '@shopify/cli-kit/node/output' | ||
|
|
||
| const MAX_PROMPT_RETRIES = 2 | ||
|
|
||
|
|
@@ -51,52 +51,32 @@ export async function selectOrCreateApp( | |
| const tomls = (cachedData?.tomls as {[key: string]: AppConfigurationFileName}) ?? {} | ||
|
|
||
| for (let attempt = 0; attempt < MAX_PROMPT_RETRIES; attempt++) { | ||
| try { | ||
| // eslint-disable-next-line no-await-in-loop | ||
| const app = await selectAppPrompt( | ||
| searchForAppsByNameFactory(developerPlatformClient, org.id), | ||
| apps, | ||
| hasMorePages, | ||
| {directory: options.directory}, | ||
| ) | ||
| // eslint-disable-next-line no-await-in-loop | ||
| const app = await selectAppPrompt( | ||
| searchForAppsByNameFactory(developerPlatformClient, org.id), | ||
| apps, | ||
| hasMorePages, | ||
| {directory: options.directory}, | ||
| ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Retry behavior removed for prompt failures; loop no longer matches intent The PR removes the Impact:
|
||
|
|
||
| const selectedToml = tomls[app.apiKey] | ||
| if (selectedToml) setCachedCommandTomlPreference(selectedToml) | ||
| const selectedToml = tomls[app.apiKey] | ||
| if (selectedToml) setCachedCommandTomlPreference(selectedToml) | ||
|
|
||
| // eslint-disable-next-line no-await-in-loop | ||
| const fullSelectedApp = await developerPlatformClient.appFromIdentifiers(app.apiKey) | ||
|
|
||
| if (!fullSelectedApp) { | ||
| throw new BugError( | ||
| `Unable to fetch app ${app.apiKey} from Shopify`, | ||
| 'Try running `shopify app config link` to connect to an app you have access to.', | ||
| ) | ||
| } | ||
| // eslint-disable-next-line no-await-in-loop | ||
| const fullSelectedApp = await developerPlatformClient.appFromIdentifiers(app.apiKey) | ||
|
|
||
| if (fullSelectedApp) { | ||
| return fullSelectedApp | ||
| } catch (error) { | ||
| // Don't retry BugError - those indicate actual bugs, not transient issues | ||
| if (error instanceof BugError) { | ||
| throw error | ||
| } | ||
|
|
||
| const errorObj = error as Error | ||
|
|
||
| // Log each attempt for observability | ||
| outputDebug(`App selection attempt ${attempt + 1}/${MAX_PROMPT_RETRIES} failed: ${errorObj.message}`) | ||
|
|
||
| // If we have retries left, inform user and retry | ||
| if (attempt < MAX_PROMPT_RETRIES - 1) { | ||
| outputInfo('App selection failed. Retrying...') | ||
| } else { | ||
| throw new BugError(errorObj.message, TRY_MESSAGE) | ||
| } | ||
| } | ||
| // If we have retries left, inform user and retry | ||
| if (attempt < MAX_PROMPT_RETRIES - 1) { | ||
| outputInfo('App selection failed. Retrying...') | ||
| } | ||
| } | ||
|
|
||
| // User-facing error message with key diagnostic info | ||
| const errorMessage = [ | ||
| 'Unable to select an app: the selection prompt was interrupted multiple times.', | ||
| 'Unable to select an app: the selection prompt failed multiple times.', | ||
| '', | ||
| `Available apps: ${apps.length}`, | ||
| ].join('\n') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-null assertion can crash with unhelpful error (diagnostics regression)
selectAppPromptnow returnscurrentAppChoices.find((app) => app.apiKey === apiKey)!. IfrenderAutocompletePromptreturns a value not present incurrentAppChoices(the incident described in the PR links),find(...)returnsundefinedand!can cause a runtime failure with a generic error instead of a targeted, actionable message.Impact:
shopify app devcan crash during selection with a confusing error, blocking development.