-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Error instead of silently failing when browsing an unreachable environment #4590
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 |
|---|---|---|
|
|
@@ -102,6 +102,7 @@ import { | |
| getCommandPaletteMode, | ||
| ITEM_ICON_CLASS, | ||
| RECENT_THREAD_LIMIT, | ||
| resolveBrowseAvailability, | ||
| } from "./CommandPalette.logic"; | ||
| import { orderItemsByPreferredIds, sortLogicalProjectsForSidebar } from "./Sidebar.logic"; | ||
| import { resolveEnvironmentOptionLabel } from "./BranchToolbar.logic"; | ||
|
|
@@ -715,10 +716,16 @@ function OpenCommandPaletteDialog(props: { | |
| const browseDirectoryPath = isBrowsing ? getBrowseDirectoryPath(query) : ""; | ||
| const browseFilterQuery = | ||
| isBrowsing && !hasTrailingPathSeparator(query) ? getBrowseLeafPathSegment(query) : ""; | ||
| // Browsing resolves paths on the selected environment's filesystem. Don't | ||
| // issue the request at all unless that environment is actually connected — | ||
| // otherwise the failure is indistinguishable from an empty directory. | ||
| const browseEnvironmentConnection = browseEnvironment?.connection ?? null; | ||
| const isBrowseEnvironmentConnected = browseEnvironmentConnection?.phase === "connected"; | ||
| const browseQuery = useEnvironmentQuery( | ||
| isBrowsing && | ||
| browseDirectoryPath.length > 0 && | ||
| browseEnvironmentId !== null && | ||
| isBrowseEnvironmentConnected && | ||
| !relativePathNeedsActiveProject | ||
| ? filesystemEnvironment.browse({ | ||
| environmentId: browseEnvironmentId, | ||
|
|
@@ -731,6 +738,13 @@ function OpenCommandPaletteDialog(props: { | |
| ); | ||
| const browseResult = browseQuery.data; | ||
| const isBrowsePending = browseQuery.isPending; | ||
| const browseAvailability = resolveBrowseAvailability({ | ||
| environmentLabel: browseEnvironment?.label ?? null, | ||
| connectionPhase: browseEnvironmentConnection?.phase ?? null, | ||
| connectionError: browseEnvironmentConnection?.error ?? null, | ||
| }); | ||
| const browseUnavailableMessage = | ||
| isBrowsing && browseAvailability._tag === "Unavailable" ? browseAvailability.message : null; | ||
| const browseEntries = browseResult?.entries ?? EMPTY_BROWSE_ENTRIES; | ||
| const { filteredEntries: filteredBrowseEntries, exactEntry: exactBrowseEntry } = useMemo( | ||
| () => filterBrowseEntries({ browseEntries, browseFilterQuery, highlightedItemValue }), | ||
|
|
@@ -1271,6 +1285,32 @@ function OpenCommandPaletteDialog(props: { | |
| }) => { | ||
| const rawCwd = input.rawCwd; | ||
|
|
||
| // The path is resolved on the target environment, so refuse outright when | ||
| // that environment is unreachable rather than dispatching an add that can | ||
| // only fail. Reuse the browse verdict so the toast states the reason | ||
| // ("<env> isn't connected.") rather than a bare status word. | ||
| const targetEnvironment = | ||
| environments.find((environment) => environment.environmentId === input.environmentId) ?? | ||
| null; | ||
| const targetAvailability = | ||
| targetEnvironment === null | ||
| ? null | ||
| : resolveBrowseAvailability({ | ||
| environmentLabel: targetEnvironment.label, | ||
| connectionPhase: targetEnvironment.connection.phase, | ||
| connectionError: targetEnvironment.connection.error, | ||
| }); | ||
| if (targetAvailability?._tag === "Unavailable") { | ||
| toastManager.add( | ||
| stackedThreadToast({ | ||
| type: "error", | ||
| title: "Failed to add project", | ||
| description: targetAvailability.message, | ||
| }), | ||
| ); | ||
| return; | ||
| } | ||
|
Contributor
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. Missing env skips refuse guardLow Severity When Reviewed by Cursor Bugbot for commit fc2294e. Configure here.
Contributor
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. Guard blocks opening existing projectsMedium Severity The new availability refuse runs before Additional Locations (1)Reviewed by Cursor Bugbot for commit fc2294e. Configure here. |
||
|
|
||
| if (isUnsupportedWindowsProjectPath(rawCwd.trim(), input.platform)) { | ||
| toastManager.add( | ||
| stackedThreadToast({ | ||
|
|
@@ -1603,17 +1643,24 @@ function OpenCommandPaletteDialog(props: { | |
| if (addProjectCloneFlow?.step === "repository") { | ||
| displayedGroups = []; | ||
| } else if (addProjectCloneFlow?.step === "confirm") { | ||
| displayedGroups = relativePathNeedsActiveProject ? [] : cloneDestinationBrowseGroups; | ||
| displayedGroups = | ||
| relativePathNeedsActiveProject || browseUnavailableMessage !== null | ||
| ? [] | ||
| : cloneDestinationBrowseGroups; | ||
| } else if (isBrowsing) { | ||
| displayedGroups = relativePathNeedsActiveProject ? [] : browseGroups; | ||
| displayedGroups = | ||
| relativePathNeedsActiveProject || browseUnavailableMessage !== null ? [] : browseGroups; | ||
| } | ||
|
|
||
| const inputPlaceholder = | ||
| remoteProjectInputPlaceholder(addProjectCloneFlow) ?? | ||
| getCommandPaletteInputPlaceholder(paletteMode); | ||
| const isSubmenu = paletteMode === "submenu" || paletteMode === "submenu-browse"; | ||
| const hasHighlightedBrowseItem = highlightedItemValue?.startsWith("browse:") ?? false; | ||
| const canSubmitBrowsePath = isBrowsing && !relativePathNeedsActiveProject; | ||
| // An unreachable environment can't confirm whether the path exists, so never | ||
| // offer to add — or worse, create — a directory we were unable to inspect. | ||
| const canSubmitBrowsePath = | ||
| isBrowsing && !relativePathNeedsActiveProject && browseUnavailableMessage === null; | ||
| const willCreateProjectPath = | ||
| canSubmitBrowsePath && | ||
| !isBrowsePending && | ||
|
|
@@ -1966,13 +2013,14 @@ function OpenCommandPaletteDialog(props: { | |
| aria-label={`${submitActionLabel} (${addShortcutLabel})`} | ||
| disabled={ | ||
| relativePathNeedsActiveProject || | ||
| browseUnavailableMessage !== null || | ||
| (isCloneDestinationStep && isRemoteProjectPending) | ||
| } | ||
| onMouseDown={(event) => { | ||
| event.preventDefault(); | ||
| }} | ||
| onClick={() => { | ||
| if (relativePathNeedsActiveProject) { | ||
| if (relativePathNeedsActiveProject || browseUnavailableMessage !== null) { | ||
| return; | ||
| } | ||
| if (isCloneDestinationStep) { | ||
|
|
@@ -2029,16 +2077,18 @@ function OpenCommandPaletteDialog(props: { | |
| ? "Enter a Git clone URL and press Enter to continue." | ||
| : "Enter a repository path and press Enter to look it up.", | ||
| } | ||
| : addProjectCloneFlow?.step === "confirm" | ||
| ? { emptyStateMessage: "Choose a destination path and press Enter to clone." } | ||
| : relativePathNeedsActiveProject | ||
| ? { emptyStateMessage: "Relative paths require an active project." } | ||
| : willCreateProjectPath | ||
| ? { | ||
| emptyStateMessage: | ||
| "Press Enter to create this folder and add it as a project.", | ||
| } | ||
| : {})} | ||
| : browseUnavailableMessage !== null | ||
| ? { emptyStateMessage: browseUnavailableMessage } | ||
| : addProjectCloneFlow?.step === "confirm" | ||
| ? { emptyStateMessage: "Choose a destination path and press Enter to clone." } | ||
| : relativePathNeedsActiveProject | ||
| ? { emptyStateMessage: "Relative paths require an active project." } | ||
| : willCreateProjectPath | ||
| ? { | ||
| emptyStateMessage: | ||
| "Press Enter to create this folder and add it as a project.", | ||
| } | ||
| : {})} | ||
| /> | ||
| </CommandPanel> | ||
| <CommandFooter className="gap-3 max-sm:flex-col max-sm:items-start"> | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.