Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 10, 2025

Problem

When Python environment creation fails (e.g., due to executables blocked by group policy or missing dependencies), users receive no feedback in the main UI. The operation silently fails, leaving users confused about what went wrong. Errors are only logged to the output channel, which most users never check.

Example from issue #XXX:

2025-10-09 13:28:38.836 [info] Running: uv --version
2025-10-09 13:28:38.838 [error] Failed to create virtual environment: Error: spawn UNKNOWN

The user sees nothing in the UI - no error dialog, no notification, no indication that the operation failed.

Root Cause

The child_process.spawn() calls in the environment creation code lacked error event handlers. When spawning a process fails (before it can even exit with a non-zero code), Node.js emits an error event on the child process. Without a handler for this event, the error was caught generically, logged, but never displayed to the user.

Additionally, even when errors were properly caught and stored in the CreateEnvironmentResult object, the calling code only checked for successful creation (if (result?.environment)) without a corresponding check to display errors when creation failed.

Solution

This PR adds two-level error handling:

1. Spawn Error Handlers (Low Level)

Added proc.on('error', ...) handlers to catch spawn failures immediately:

  • runUV() in src/managers/builtin/helpers.ts
  • runPython() in src/managers/builtin/helpers.ts
  • _runConda() in src/managers/conda/condaUtils.ts

These handlers log the error and reject the promise with a descriptive message.

2. User Error Display (High Level)

Added error message display when environment creation fails:

  • venvManager.ts: Check result?.envCreationErr and call showErrorMessage()
  • condaEnvManager.ts: Add showErrorMessage() in catch block

All error messages use localized strings via l10n.t() and include the actual error details.

Example

Before this fix:

// User clicks "Create Environment"
// Process spawn fails with UNKNOWN error
// User sees: (nothing - operation appears to do nothing)

After this fix:

// User clicks "Create Environment"  
// Process spawn fails with UNKNOWN error
// User sees: "Failed to create virtual environment: Error spawning uv: spawn UNKNOWN"

Impact

  • Users now receive clear error messages in the UI when environment creation fails
  • Error messages include the actual failure reason (spawn errors, permission issues, etc.)
  • Both venv and conda environment managers properly report failures
  • Errors are still logged to the output channel for debugging
  • No impact on successful operations

Testing

  • ✅ Code compiles successfully with npm run compile
  • ✅ Linter passes with npm run lint
  • ✅ Changes follow existing code patterns and use proper localization
  • Manual testing recommended for:
    • Executables blocked by group policy (original issue scenario)
    • Missing Python/UV/conda installations
    • Invalid environment names or paths
    • Permission errors

Fixes #XXX

Original prompt

This section details on the original issue you should resolve

<issue_title>[Python Environments] No report of failure when environment is not created</issue_title>
<issue_description>
Type: Bug

When I run the command for creating a Python virtual environment, nothing happens. No env is created, but there are no error-messages either.

If I run the traditional command myself, in the terminal (python -m venv .venv), I get an error-message, saying the program is blocked by group policy (WinError 1260). Maybe that is why it is not working when doing it from VS Code, but in that case, there should be some kind of error-message.

UPDATE: Another error happened that showed up in the User Interface, and offered to let me look into the logs, When I got there, I see that there are log-entries for all my retrys of creating the virtual environment. So the problem is maybe twofold:

  1. it doesn't work (probably because of policies on my employers computers)
  2. it doesn't give any feedback in the main UI that the operation failed

This is how it shows in the log when I use the option "Quick Create":

2025-10-09 13:28:38.836 [info] Running: uv --version
2025-10-09 13:28:38.838 [error] Failed to create virtual environment: Error: spawn UNKNOWN
Environment Information
Extension Version: 1.8.0
Python Extension Version: 2025.14.0

Registered Environment Managers (2):
  - ms-python.python:system (Global)
  - ms-python.python:venv (venv)

Total Available Environments: 1
Environment Details:
  1. Python 3.13 (3.13.8.final.0) - C:\Users\stsk\AppData\Local\Microsoft\WindowsApps\python3.13.exe

Python Projects (1):
  1. c:\python
     Environment: Python 3.13

Extension Settings:
  Default Environment Manager: ms-python.python:venv
  Default Package Manager: ms-python.python:pip
Auto-activation is "command". Activation based on first 'py-env.terminal.autoActivationType' setting which is 'command' and 'python.terminal.activateEnvironment' if the first is undefined which is 'true'.

Extension version: 1.8.0
VS Code version: Code 1.104.3 (385651c938df8a906869babee516bffd0ddb9829, 2025-10-02T12:30:51.747Z)
OS version: Windows_NT x64 10.0.26100
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) Ultra 5 125U (14 x 2688)
GPU Status 2d_canvas: enabled
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 15.47GB (0.41GB free)
Process Argv C:\Users\stsk\Documents\Archi\scripts\examples\Anonymize.ajs --crash-reporter-id e2e5a566-bed1-48e9-b34d-3d6701776fa6
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
pythonvspyt551:31249599
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
pythonrdcb7:31342333
usemplatestapi:31297334
aj953862:31281341
cs4_fixed:31391938
nes-set-on:31351930
6abeh943:31336334
envsactivate1:31353494
0cj2b977:31352657
gendocstringt:31395207
cloudbuttont:31379625
todos-1:31390405
treatment_gpt5applypatchexclusively:31398171
3efgi100_wstrepl:31382709
trigger-command-fix:31379601
cmp-cht-code-treat-node-fetcher:31397680
auto_model_enabled:31385282
grok-v2-prompt:31398332
use-responses-api:31390855
4c5ff9_b:31397103

Comments on the Issue (you are @copilot in this section)

@eleanorjboyd Yes great point, there should be error messages added when create environment (either quick create or regular create) fails.

Fixes #920


💡 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] Fix lack of error reporting for Python environment creation Fix: Show error messages in UI when environment creation fails Oct 10, 2025
@Copilot Copilot AI requested a review from eleanorjboyd October 10, 2025 21:15
Copilot finished work on behalf of eleanorjboyd October 10, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python Environments] No report of failure when environment is not created

2 participants