PowerShell / DSC

This repo is for the DSC v3 project
MIT License
201 stars 29 forks source link

dsc set command fails when using powershellgroup resources with json error #261

Open jchancellor-ms opened 11 months ago

jchancellor-ms commented 11 months ago

Prerequisites

Steps to reproduce

When using dsc config set for a test powershellgroup resource, I get an error Operation: Failed to parse json from get pwsh|PSDscResources/MSFT_WindowsFeature. However, it then returns a valid json object so it is unclear why it is unable to parse the output.

Sample config code: `# example.dsc.config.yaml $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json resources:

And example output: { "IncludeAllSubFeature": false, "DisplayName": "DNS Server", "Name": "DNS", "Ensure": "Absent" }

When running dsc set the additional error details is Error: JSON: expected value at line 1 column 1

Expected behavior

dsc would set the configuration to match the yaml config file

Actual behavior

Error - Error: JSON: expected value at line 1 column 1

Error details

Error: JSON: expected value at line 1 column 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.9
PSEdition                      Core
GitCommitId                    7.3.9
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

7.3.9

Visuals

No response

anmenaga commented 11 months ago

@jchancellor-ms is that on dsc.exe from latest main branch? With the sample config code I am hitting #260 .

In general, Error: JSON: expected value at line 1 column 1 happens when PS returns additional output - such as warnings or verbose text (e.g. when a PS module, containg the DSC resource, has functions/cmdlets that do Not follow PS naming convention). We've added a workaround for most of such cases, but looks like not all.

jchancellor-ms commented 11 months ago

I'm using build Alpha.3 as I was trying to avoid figuring out how to build the latest dsc executable. After submitting issue #260, I added some temporary code to the powershell file to get around the inputs issue and see if I could get a functioning implementation for a customer demo for additional feedback. I was able to get past 260, but then ran into this issue where the output appears to return valid output, but fails the json check. I suspect the real issue for both these issues is that since we're wrapping Invoke-DSCResource, it needs to be smart enough to throw away unneeded inputs during a get, and have a way to return the output without extraneous characters.