Skip to content

Fix Watson #1488201: Surface cookiecutter install failures without crashing VS#8511

Merged
StellaHuang95 merged 1 commit into
mainfrom
fix-watson-1488201-cookiecutter-waitforoutput
May 29, 2026
Merged

Fix Watson #1488201: Surface cookiecutter install failures without crashing VS#8511
StellaHuang95 merged 1 commit into
mainfrom
fix-watson-1488201-cookiecutter-waitforoutput

Conversation

@StellaHuang95
Copy link
Copy Markdown
Contributor

Issue

Watson #1488201CLR_EXCEPTION_Microsoft.CookiecutterTools.Model.ProcessException from CookiecutterClient.WaitForOutput (12 hits, builds 17.11.35219.272 – 18.3.11520.95).

Problem

The cookiecutter feature creates a side venv, installs pip, then pip install cookiecutter. If any of those subprocesses fail (no network, corporate proxy blocking PyPI, corrupt interpreter), the subprocess exits non-zero, WaitForOutput throws ProcessException, and the exception escapes the WPF Dispatcher → crashes VS.

The original code in CreateCookiecutterEnv wrapped only the first install step in try { … } throw new CriticalException(...). The outer handler in CookiecutterViewModel.EnsureCookiecutterIsInstalledAsync uses catch (Exception ex) when (!ex.IsCriticalException()) — so the wrapped CriticalException propagated uncaught anyway, and the other two install paths (pip install pip, pip install cookiecutter) had no guard at all.

Fix

  • Add helper WaitForCookiecutterInstallOutput(...) that wraps WaitForOutput, catches ProcessException, writes a formatted error + stderr lines to _redirector, and re-throws as InvalidOperationException. InvalidOperationException is non-critical, so the outer handler catches it cleanly → sets status to Failed, returns false, fires telemetry.
  • Route all three install-path WaitForOutput calls through the new helper.
  • Remove the old throw new CriticalException(...) wrap in CreateCookiecutterEnv (the comment claiming it was "needed for EnsureCookiecutterIsInstalledAsync to fail properly" was incorrect — it actually crashed VS).
  • Add localized string CookiecutterInstallFailed for the formatted error message.

Files changed

  • Python/Product/Cookiecutter/Model/CookiecutterClient.cs
  • Python/Product/Cookiecutter/Strings.resx
  • Python/Product/Cookiecutter/Strings.Designer.cs

@StellaHuang95 StellaHuang95 requested a review from a team as a code owner May 28, 2026 22:10
…ashing VS

WaitForOutput throws ProcessException when a subprocess (venv creation,
pip install, etc.) exits non-zero. The install paths
(CreateVenvWithoutPipThenInstallPip and InstallPackage) did not catch it,
and CreateCookiecutterEnv re-wrapped it as CriticalException to 'fail
properly' - but the outer catch in
CookiecutterViewModel.EnsureCookiecutterIsInstalledAsync explicitly
ignores critical exceptions (when !ex.IsCriticalException()), so the
CriticalException escaped the message-loop boundary and crashed VS.

  * Add private WaitForCookiecutterInstallOutput helper that catches
    ProcessException, writes a friendly message + the captured stderr
    to the redirector, and rethrows as InvalidOperationException.
  * Use the helper at the three install-path WaitForOutput call sites
    (lines 167, 184, 212 of CookiecutterClient.cs).
  * Drop the CriticalException re-wrap in CreateCookiecutterEnv - the
    outer catch in EnsureCookiecutterIsInstalledAsync already handles
    non-critical exceptions and surfaces the failure to the user.
  * Add Strings.CookiecutterInstallFailed resource string.

Watson #1488201 - 12 hits, builds 17.11.35219.272 - 18.3.11520.95.
@StellaHuang95 StellaHuang95 force-pushed the fix-watson-1488201-cookiecutter-waitforoutput branch from c66d692 to 551f18a Compare May 28, 2026 22:16
@sonarqubecloud
Copy link
Copy Markdown

@StellaHuang95
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Contributor

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

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

Approved via Review Center.

@StellaHuang95 StellaHuang95 merged commit 3b78319 into main May 29, 2026
8 checks passed
@StellaHuang95 StellaHuang95 deleted the fix-watson-1488201-cookiecutter-waitforoutput branch May 29, 2026 00:17
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.

2 participants