DSC
DSC copied to clipboard
DSC doesnt propagate exit code correctly
Prerequisites
- [x] Write a descriptive title.
- [x] Make sure you are able to repro it on the latest version
- [x] 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:
Doing the same in the engine results in an exit code 2, even though it tells me 3:
Steps to reproduce
- 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
}
}
)
}
- 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
I don't know that the design for DSC included propagating errors from resources to DSC itself - exit code 2 for DSC maps to EXIT_DSC_ERROR:
https://github.com/PowerShell/DSC/blob/e0a71a84c3636b87ba6faf54f6325204a23a075a/dsc/src/util.rs#L50-L58
Resource exit codes tell the higher order tool (in this case, DSC) what went wrong so that information can be surfaced, but consider a case where two different resources exit with a non-zero code - which one should DSC use?
I could certainly see an argument for the dsc resource commands to propagate the exit code, but I don't think it makes sense for the dsc config commands.
Sharp Mikey, I didn't think about that one. I was assuming that it would map one-on-one with the resource manifest.
@michaeltlombardi - is this the issue that will address getting the errors? https://github.com/PowerShell/DSC/issues/423
@michaeltlombardi - is this the issue that will address getting the errors? #423
That will certainly help for the messaging, but PSDSC resources don't (currently) have exit codes, so we don't have a way to map them for higher order tools. Implicitly, PSDSC resources all exit either 0 (success) or 1 (failure).
I don't think we want to propagate exit codes directly from resource to DSC for dsc config commands, but we probably do for dsc resource invocation commands.