Details of the scenario you tried and the problem that is occurring
When a resource have an schema.mof that is not correct and the method ImportClasses returns exceptions in the variable $exceptionCollection they are not handled.
|
$tempFilePath, $moduleInfo, $exceptionCollection |
Steps to reproduce the problem
Have a resource with the schema.mof where there are two spaces after the colon and before the super class OMI_BaseResource, e.g. : OMI_BaseResource.
[ClassVersion("1.0.0"), FriendlyName("xDnsServerForwarder")]
class MSFT_xDnsServerForwarder : OMI_BaseResource
{
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
[Write] String IPAddresses[];
[Write, Description("Validate if you want to use root hint on DNS Server.")] Boolean UseRootHint;
};
Expected behavior
Should throw the exception that is returned.
Current behavior
Just returns with $null and does not throw an exception.
Suggested solution to the issue
Make sure to throw the (first) exception.
if ($exceptionCollection)
{
# Throw the first exception that was returned from ImportClasses().
throw $exceptionCollection[0]
}
This will return for example the following error so it would need a localized error message saying what schema file generated the error.
ERROR: Cim deserializer threw an error when deserializing file C:\Users\JOHAN~1.LJU\AppData\Local\Temp\DscMofHelper_30c3f093-e2f0-4794-841e-47c551db2105.tmp.
Running Get-Error will then return the full error in the InnerExeception (at least in this case).
InnerException :
Type : Microsoft.Management.Infrastructure.CimException
NativeErrorCode : Failed
ErrorData : OMI_Error
StatusCode : 1
TargetSite :
Name : ThrowIfMiResultFailure
DeclaringType : Microsoft.Management.Infrastructure.CimException
MemberType : Method
Module : Microsoft.Management.Infrastructure.dll
StackTrace :
at Microsoft.Management.Infrastructure.CimException.ThrowIfMiResultFailure(MiResult result, String errorMessage, InstanceHandle errorData)
at Microsoft.Management.Infrastructure.CimException.ThrowIfMiResultFailure(MiResult result, InstanceHandle errorData)
at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer.DeserializeClassHandle(Byte[] serializedData, UInt32& offset, IEnumerable`1 cimClasses, String computerName, String
namespaceName, OnClassNeeded onClassNeededCallback, GetIncludedFileContent getIncludedFileCallback)
at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer.DeserializeClasses(Byte[] serializedData, UInt32& offset, IEnumerable`1 classes, String computerName, String namespaceName, OnClassNeeded onClassNeededCallback, GetIncludedFileContent getIncludedFileCallback)
at Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser.ParseSchemaMof(String filePath)
Message : Class 'MSFT_xDnsServerForwarder' has undefined super class 'OMI_BaseResource'
At line:7, char:2
Buffer:
Boolean UseRootHint;
};^
Source : Microsoft.Management.Infrastructure
HResult : -2146233088
The operating system the target node is running
Windows 10
Version and build of PowerShell the target node is running
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Version of the module that was used
0.4.0
Details of the scenario you tried and the problem that is occurring
When a resource have an schema.mof that is not correct and the method
ImportClassesreturns exceptions in the variable$exceptionCollectionthey are not handled.DscResource.DocGenerator/source/Private/Get-MofSchemaObject.ps1
Line 79 in e161d60
Steps to reproduce the problem
Have a resource with the schema.mof where there are two spaces after the colon and before the super class
OMI_BaseResource, e.g.: OMI_BaseResource.Expected behavior
Should throw the exception that is returned.
Current behavior
Just returns with
$nulland does not throw an exception.Suggested solution to the issue
Make sure to throw the (first) exception.
This will return for example the following error so it would need a localized error message saying what schema file generated the error.
Running
Get-Errorwill then return the full error in the InnerExeception (at least in this case).The operating system the target node is running
Windows 10
Version and build of PowerShell the target node is running
Version of the module that was used
0.4.0