Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-MofSchemaObject: Missing error handling when calling method ImportClasses #26

Open
johlju opened this issue Mar 5, 2020 · 0 comments
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.

Comments

@johlju
Copy link
Member

johlju commented Mar 5, 2020

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

@johlju johlju changed the title Get-MofSchemaObject: Missing error handling When calling method ImportClasses there are no error handling Get-MofSchemaObject: Missing error handling when calling method ImportClasses Mar 5, 2020
@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

1 participant