PowerShell / PowerShell/DSC

DSC doesnt propagate exit code correctly

Open
#817 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug Need-Review
Dominant language
Rust
Stars
523
Forks
75
Avg merge
3d 16h
Merged PRs (30d)
24

Description

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

I am experiencing an issue when creating a custom DSC v3 resource. This was discovered while developing the win32service using Python. The resource needs to be elevated to get data from the SCM. If it is not elevated, it will throw an access denied error.

I'm capturing this error to later propagate it to DSC's engine in the resource manifest as such:

"exitCodes": {
        "0": "Success",
        "1": "Invalid parameter",
        "2": "Invalid input",
        "3": "Service error",
        "4": "JSON serialization failed"
    },

When looking at both, I can see the following:

Image

Doing the same in the engine results in an exit code 2, even though it tells me 3:

Image

Steps to reproduce
  1. Create the following configuration document
$config = @{
            '$schema' = 'https://aka.ms/dsc/schemas/v3/bundled/config/document.json'
            resources = @(
                @{
                    name = 'service'
                    type = 'DSCResources.Windows/Win32Service'
                    properties = @{
                        name = 'NewService'
                        path       = (Get-Process -Id $PID).Path
                        _exist = $true
                    }
                }
            )
        }
  1. Run dsc config set --input ($config | ConvertTo-Json -Depth 10)

If you need access to the repository containing the resource, let me know

Expected behavior
The exit code should be 3
Actual behavior
The exit code is 2
Error details

Environment data
Name                           Value
----                           -----
PSVersion                      7.4.7
PSEdition                      Core
GitCommitId                    7.4.7
OS                             Microsoft Windows 10.0.19045
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.1.0-preview.5

Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named in the report. Start by reproducing dsc config set --input ... with the custom Python resource, then trace how its manifest exit code reaches the DSC engine. Done means the command reports exit code 3 instead of 2, with regression coverage for this propagation path.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, python, rust
Domain
backend, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.