Fix: Show error messages in UI when environment creation fails #933
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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 lackederror
event handlers. When spawning a process fails (before it can even exit with a non-zero code), Node.js emits anerror
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()
insrc/managers/builtin/helpers.ts
runPython()
insrc/managers/builtin/helpers.ts
_runConda()
insrc/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
: Checkresult?.envCreationErr
and callshowErrorMessage()
condaEnvManager.ts
: AddshowErrorMessage()
in catch blockAll error messages use localized strings via
l10n.t()
and include the actual error details.Example
Before this fix:
After this fix:
Impact
Testing
npm run compile
npm run lint
Fixes #XXX
Original prompt
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.