fix(scripts): send check-prerequisites.ps1 errors to stderr#3123
Conversation
The validation errors and run-hints in check-prerequisites.ps1 were written with Write-Output, so they went to stdout. This script is usually run with -Json and its stdout parsed by the agent, so an error (e.g. missing plan.md) leaves the parser with an error string instead of JSON. The bash counterpart already writes these to stderr (>&2), as do the sibling PowerShell scripts (setup-tasks.ps1, common.ps1's Get-FeaturePathsEnv). Switch the six error/hint lines to [Console]::Error.WriteLine so stdout stays clean and the two shells match.
There was a problem hiding this comment.
Pull request overview
Aligns the PowerShell prerequisite checker with the bash version by ensuring validation failures don’t pollute -Json stdout output, preventing downstream JSON parsing errors in agent/automation consumers.
Changes:
- Switched prerequisite validation error/hint messaging from
Write-Output(stdout) to[Console]::Error.WriteLine(...)(stderr). - Preserved the success-path behavior and JSON payload output (only failure-path messaging stream changed).
Show a summary per file
| File | Description |
|---|---|
| scripts/powershell/check-prerequisites.ps1 | Routes prerequisite failure messages to stderr so -Json stdout remains valid JSON for consumers. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
|
Can you also address the requested test changes as per #3122 bug assessment? |
Per the github#3122 bug assessment, tighten the failure-path tests so they verify stdout stays clean (empty / valid JSON) and the error text only appears on stderr, instead of checking the combined stdout+stderr string. Covers all three PowerShell validation paths (missing feature dir, missing plan.md, missing tasks.md with -RequireTasks) and the bash counterpart. The two new error-routing tests fail on the pre-fix script (errors on stdout) and pass after it.
|
done - tightened the failure-path tests to assert stdout stays clean (empty/valid json) and the error only shows on stderr, instead of the old combined stdout+stderr check. added cases for the missing plan.md and missing tasks.md (-RequireTasks) paths too. confirmed the two error-routing tests fail on the pre-fix script and pass after the fix. |
|
Thank you! |
closes #3122
check-prerequisites.ps1wrote its validation errors and run-hints withWrite-Output, so they went to stdout. the script is usually run with-Jsonand its stdout is parsed as json by the agent, so when validation fails (e.g. missing plan.md) the parser gets an error string instead of json and breaks.the bash counterpart already sends these to stderr (
>&2), and the sibling powershell scripts (setup-tasks.ps1,common.ps1'sGet-FeaturePathsEnv) already use[Console]::Error.WriteLine. this switches the six error/hint lines incheck-prerequisites.ps1to[Console]::Error.WriteLineso stdout stays clean and the two shells behave the same.no behaviour change on the success path - only the failure paths, which still
exit 1.note: i used an ai assistant to help investigate and prepare this change. disclosing per CONTRIBUTING.md.