Skip to content

Fix PyEnv section endlessly spinning when pyenv is not installed #438

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

Closed
wants to merge 2 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 20, 2025

Issue

When pyenv is not installed on a user's machine, the PyEnv section in the Python Environments view shows an infinite loading spinner when expanded:

Image

Root Cause

In the refreshPyenv function, when pyenv is not found initially, the code tries to get it from the NativePythonFinder data. However, it doesn't check if any pyenv managers were found before trying to access managers[0].executable:

if (pyenv === undefined) {
    const managers = data
        .filter((e) => !isNativeEnvInfo(e))
        .map((e) => e as NativeEnvManagerInfo)
        .filter((e) => e.tool.toLowerCase() === 'pyenv');
    pyenv = managers[0].executable; // Error when managers is empty
    await setPyenv(pyenv);
}

This causes an error when pyenv is not installed, leaving the UI in an infinite loading state.

Fix

Added a check to ensure the managers array has elements before trying to access the first one:

if (pyenv === undefined) {
    const managers = data
        .filter((e) => !isNativeEnvInfo(e))
        .map((e) => e as NativeEnvManagerInfo)
        .filter((e) => e.tool.toLowerCase() === 'pyenv');
    
    if (managers.length > 0) {
        pyenv = managers[0].executable;
        await setPyenv(pyenv);
    }
}

This ensures the UI doesn't get stuck in a loading state when pyenv is not installed on the system.

Fixes #437.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] PyEnv endlessly spins Fix PyEnv section endlessly spinning when pyenv is not installed May 20, 2025
@Copilot Copilot AI requested a review from karthiknadig May 20, 2025 21:40
Copilot finished work on behalf of karthiknadig May 20, 2025 21:40
Copy link
Member

@karthiknadig karthiknadig left a comment

Choose a reason for hiding this comment

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

registerEnvironmentManager should not be called if pyenv is not found on the machine.

Copy link
Contributor Author

Copilot AI commented May 21, 2025

registerEnvironmentManager should not be called if pyenv is not found on the machine.

I've updated the code to ensure registerEnvironmentManager is only called when pyenv is found on the machine. Previously, we were only checking for exceptions but not validating the return value of getPyenv(). The fix (fc8f621) ensures we only register the PyEnv manager when a valid pyenv executable is found.

Copilot finished work on behalf of karthiknadig May 21, 2025 03:02
@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label May 21, 2025
@karthiknadig karthiknadig marked this pull request as ready for review May 21, 2025 03:23
@karthiknadig karthiknadig enabled auto-merge (squash) May 21, 2025 03:25
@karthiknadig karthiknadig self-requested a review May 21, 2025 03:26
@karthiknadig karthiknadig dismissed their stale review May 21, 2025 03:26

comments addressed.

@karthiknadig karthiknadig removed their request for review May 21, 2025 13:50
Copilot AI and others added 2 commits May 21, 2025 07:45
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
auto-merge was automatically disabled May 21, 2025 15:37

Pull request was closed

@karthiknadig karthiknadig reopened this May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

Error loading sessions

Retrying...

Successfully merging this pull request may close these issues.

PyEnv endlessly spins Raise error: Cannot read properties of undefined (reading 'executable')
4 participants