{{ message }}
fix: capture cmdlet warnings to prevent stdout contamination breaking DSC JSON parsing#2000
Open
Gijsreyn wants to merge 2 commits into
Open
fix: capture cmdlet warnings to prevent stdout contamination breaking DSC JSON parsing#2000Gijsreyn wants to merge 2 commits into
Gijsreyn wants to merge 2 commits into
Conversation
… DSC JSON parsing
Author
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR aims to prevent PSResourceGet warning output from contaminating DSC JSON output (stdout), which can break JSON parsing, and adds a regression test to validate stdout remains valid JSON.
Changes:
- Added a Pester regression test ensuring
dsc resource set ... -o jsonstdout contains only valid JSON (no warnings / ANSI escapes). - Captured warnings from
Install-PSResource/Uninstall-PSResourcevia-WarningVariableand forwarded them toWrite-Trace. - Set
$WarningPreference = 'SilentlyContinue'to suppress warnings globally within the DSC entry script.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

PR Summary
Warnings emitted by
Install-PSResourceandUninstall-PSResourcewere leaking to stdout, corrupting the JSON output that DSC parses after each set operation. This fix suppresses the warning stream globally in the DSC script and re-routes any per-cmdlet warnings through the trace (stderr) channel so they remain visible without breaking JSON parsing.PR Context
DSC expects each resource operation to emit only valid JSON on stdout. PowerShell warning messages (e.g. from NuGet or module compatibility checks) were being written to stdout alongside the JSON output, causing DSC to fail when parsing the response. The fix sets
$WarningPreference = 'SilentlyContinue'at the script level to prevent any unintentional warning output, while individually capturing-WarningVariableonInstall-PSResourceandUninstall-PSResourceand forwarding those throughWrite-Traceatwarnlevel so they still appear in DSC's trace/stderr stream.Note
It's difficult to reproduce a warning in the stream on the GitHub runners; thus, I added a simple regression test.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.