Discovery of registry resource gives none-descriptive error message.
Prerequisites
- [X] Write a descriptive title.
- [X] Make sure you are able to repro it on the latest version
- [X] Search the existing issues.
Steps to reproduce
PS C:\Onebranch\dscv3\DSC> dsc resource get -r Microsoft.Windows/Registry
Error: Command: Resource 'Microsoft.Windows/Registry' [Exit code 2] Error JSON does not match schema: EOF while parsing a value at line 1 column 0
PS C:\Onebranch\dscv3\DSC> dsc resource get -r Microsoft.Windows/*
Error: Command: Resource 'Microsoft.Windows/Registry' [Exit code 2] Error JSON does not match schema: EOF while parsing a value at line 1 column 0
PS C:\Onebranch\dscv3\DSC> dsc resource get -r Microsoft/OS*
actualState:
$id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
family: Windows
version: 10.0.22621
edition: Windows 11 Enterprise
bitness: '64'
Expected behavior
Find the resource with Partial and full name.
Actual behavior
Error
PS C:\Onebranch\dscv3\DSC> dsc resource get -r Microsoft.Windows/Registry
Error: Command: Resource 'Microsoft.Windows/Registry' [Exit code 2] Error JSON does not match schema: EOF while parsing a value at line 1 column 0
PS C:\Onebranch\dscv3\DSC> dsc resource get -r Microsoft.Windows/*
Error: Command: Resource 'Microsoft.Windows/Registry' [Exit code 2] Error JSON does not match schema: EOF while parsing a value at line 1 column 0
Error details
Empty /Null
Environment data
PS C:\Onebranch\dscv3\DSC> get-error | fl *
PS C:\Onebranch\dscv3\DSC> $psversionTable
Name Value
---- -----
PSVersion 7.3.6
PSEdition Core
GitCommitId 7.3.6
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Version
latest code as of this filing (private build)
Visuals
The get command gets the current state of a resource. Resources that can only manage a single instance on a node, like the timezone or system language, don't need any properties to get the current state of the instance. Resources that can manage multiple resources typically do need at least one property defined in the JSON, unless they manage a specific instance by default.
The error message being returned for the first and second commands is because the registry resource can't get the current state of an instance without properties that tell it the registry path to look for. In that case, the error being returned is indicating that it can't parse the JSON, because none was supplied. I think that error message could be improved. Ideally, the message should tell a user that the resource requires the foo and bar properties to be defined.
The OSInfo resource doesn't require any properties for retrieving current state, which is why it returns information.
I think that is different experience than what get-dscresource was in previous DSC.
PS>Get-DscResource Registry
ImplementedAs Name ModuleName Version Properties
------------- ---- ---------- ------- ----------
PowerShell Registry PSDesiredStateConfiguration 1.1 {Key, ValueName, DependsOn, Ensu...
PowerShell Registry PSDscResources 2.12.0.0 {Key, ValueName, DependsOn, Ensu...
Also, your comment
Resources that can manage multiple resources typically do need at least one property defined in the JSON, unless they manage a specific instance by default.
Any property or just the 'key' or unique identifier of the registry entry?
Any property or just the 'key' or unique identifier of the registry entry?
@BerheAbrha - right now in v3, it depends entirely on the DSC Resource's implementation. The only way to guarantee that a property is mandatory right now is to define it in the resource schema as a required property (which also makes this discoverable/surfaceable for users).
When you run registry schema (or dsc resource schema -r Microsoft.Windows/Registry), the schema declares that the keyPath property is required:
$schema: http://json-schema.org/draft-07/schema#
title: Registry
type: object
required:
- keyPath
properties:
# snipped
In prior versions of DSC, the marking of a property as a Key property signified both that the property was mandatory for all operations and that it could be used to uniquely identify an instance of the resource. There's no built-in equivalent of the unique identification behavior yet in DSCv3, but I think it could more-or-less either follow from the required keyword or be part of an extended DSC-specific dialect of JSON Schema.