Skip to content

Report why a cleanup command could not start - #121

Merged
AmirMS (AmelBawa-msft) merged 1 commit into
microsoft:mainfrom
26zl:pr/cleanup-command-errors
Sep 29, 2026
Merged

AmirMS (AmelBawa-msft) merged 1 commit into
microsoft:mainfrom
26zl:pr/cleanup-command-errors

Conversation

@26zl

Copy link
Copy Markdown
Contributor

I read through the new Uninstall code from #108 before trying it on my own machines; this is one of three small things I found there (the other two are separate PRs).

Invoke-DevConfigNativeCommand runs a bounded command in a separate runspace. When the executable cannot start at all, the error lands in the runspace's error stream, which is not read, and the function returns ExitCode and Output both $null. Invoke-DevConfigCleanupCommand then fails on $result.Output.Trim(), so the user sees

You cannot call a method on a null-valued expression.

instead of the reason. Every cleanup call takes this path (-TimeoutSeconds defaults to 900), and the per-user task script embeds the same function, so it loses the reason too. The in-process path (-TimeoutSeconds 0) already surfaces the real error.

The fix throws the first error from the runspace's error stream after EndInvoke, the same exception the in-process path throws, and builds the failure message from [string]$result.Output.

Checked before and after on Windows 11 Pro 25H2 (build 26200.9550), in pwsh 7.6.6 and in Windows PowerShell 5.1.26100 (the cleanup host), by dot-sourcing _environment.ps1 and calling Invoke-DevConfigCleanupCommand -FilePath <path>\unins000.exe -TimeoutSeconds 30 against a text file of that name: before, ExitCode=$null and the null-method message; after, Program 'unins000.exe' failed to run: ... not a valid application for this OS platform. A command that exits 7 still reports failed (7): boom, and a successful one still returns ExitCode=0.

Only src/ is touched; the signed copy is left to the sign pipeline.

Thanks for having a look.

Invoke-DevConfigNativeCommand runs a bounded command in a separate
runspace. When the executable cannot start at all, the failure lands
in that runspace's error stream, which nothing read: the function
returned ExitCode $null and Output $null, and
Invoke-DevConfigCleanupCommand then failed on $null.Trim() with "You
cannot call a method on a null-valued expression." instead of the
reason. The in-process path (TimeoutSeconds 0) surfaced the real
error. Surface the runspace error the same way, and build the failure
message from a string so a missing output cannot mask the exit code.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused changes address the reported failure without an identified regression.

Review effort: Balanced
Findings: None

What changed in this PR

This PR makes Windows Dev Config cleanup report why a command could not start instead of showing a null-value error.

Changes:

  • Throws the first error captured by the bounded command’s runspace.
  • Safely formats cleanup output when it is null.
File Description
src/​windows-dev-config/​steps/​_environment.ps1 Surfaces command-start errors and handles null cleanup output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@AmelBawa-msft
AmirMS (AmelBawa-msft) merged commit 4e76aa7 into microsoft:main Sep 29, 2026
1 check passed
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.

3 participants