Skip to content

config set throws errors for resources with "_exist: false" if they don't exist #843

@fl0p3k

Description

@fl0p3k

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Summary

When running config set command against a JSON configuration document that has a resource that has _exist set to false, an error is thrown when the resource does not actually exist, even though the desired state is for it not to exist.

Steps to reproduce

  1. Configuration document JSON

    {
      "$schema": "https://aka.ms/dsc/schemas/v3/bundled/config/document.json",
      "resources": [
        {
          "type": "Microsoft.Windows/Registry",
          "name": "EnsureTest1Value",
          "properties": {
            "keyPath": "HKEY_LOCAL_MACHINE\\SOFTWARE\\TEST",
            "valueName": "Test1",
            "valueData": { "DWord": 1 },
            "_exist": true
          }
        },
        {
          "type": "Microsoft.Windows/Registry",
          "name": "EnsureTest2Value",
          "properties": {
            "keyPath": "HKEY_LOCAL_MACHINE\\SOFTWARE\\TEST",
            "valueName": "Test2",
            "valueData": { "String": "Hello World!" },
            "_exist": true
          }
        },
        {
          "type": "Microsoft.Windows/Registry",
          "name": "EnsureTest3Value",
          "properties": {
            "keyPath": "HKEY_LOCAL_MACHINE\\SOFTWARE\\TEST",
            "valueName": "Test",
            "valueData": { "String": "Hello World!" },
            "_exist": false
          }
        }
      ]
    }
  2. Run this command to create the resource items:

    dsc config set --file C:\dsc\Demo1.json
  3. Run this command to validate the config document against the actual values.

    $Result = dsc config test --file C:\dsc\Demo1.json
    $ResultData = $Result | ConvertFrom-Json
    foreach ($res in $ResultData.results) {
        $desiredState = $res.result.desiredState.valueData
        $actualState = $res.result.actualState.valueData
        $inDesiredState = $res.result.inDesiredState
        Write-Host "$($res.name): inDesiredState = $inDesiredState`tActualState = $actualState`tDesiredState = $desiredState"
    }

Expected behavior

When running step 2, there should be no error and a JSON object ouput

When running the command in step 3, the resource check should look like this:

EnsureTest1Value: inDesiredState = True ActualState = @{DWord=1}        DesiredState = @{DWord=1}
EnsureTest2Value: inDesiredState = True ActualState = @{String=Hello World!}    DesiredState = @{String=Hello World!}
EnsureTest3Value: inDesiredState = True        ActualState =   DesiredState =

Actual behavior

When running step 2 for the first time, it throws an error (only when the resource to remove is there then no error)

$Result = dsc config set --file C:\dsc\Demo1.json
2025-05-28T18:32:52.458034Z ERROR trace_message="PID 6084: Registry value: Data not found for value with name 'Test'"
2025-05-28T18:32:52.461182Z ERROR Error: Command: Resource 'registry' [exit code 3] manifest description: Registry error

When running step 3, the resource that should not exist is showing not in desired state since it does not exist.

EnsureTest1Value: inDesiredState = True ActualState = @{DWord=1}        DesiredState = @{DWord=1}
EnsureTest2Value: inDesiredState = True ActualState = @{String=Hello World!}    DesiredState = @{String=Hello World!}
EnsureTest3Value: inDesiredState = False        ActualState =   DesiredState = @{String=Hello World!}

Error details

Environment data

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

Version

dsc 3.0.2

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions