PowerShell / DSC

This repo is for the DSC v3 project
MIT License
133 stars 22 forks source link

Use trace messaging to indicate composite resources are being ignored #424

Open michaeltlombardi opened 2 months ago

michaeltlombardi commented 2 months ago

Summary of the new feature / enhancement

As a configuration author using PSDSC resources in DSC, I always see debug messages with a warning prefix about "implementation detail not found" for composite resources when the adapter builds the DSC cache. The warning implies that something has gone wrong, but the actual behavior is desired and expected - Invoke-DscResource doesn't work with composite resources. Instead, the adapter should emit trace messages indicating that it's not caching the composite resource because they're not supported.

The code that is causing this behavior is in the Invoke-DscCacheRefresh function in the adapter module:

https://github.com/PowerShell/DSC/blob/9ee037ae9a4491d1c8a932a3224c3a281a313cc0/powershell-adapter/psDscAdapter/psDscAdapter.psm1#L78-L82

Proposed technical implementation details (optional)

Define an additional check in the foreach loop to specifically discard composite resources:

$dscResourceTypeName = $dscResource.ModuleName + '/' + $dscResource.Name

if ($dscResource.ImplementedAs -eq 'Composite') {
    $trace = @{
        'Trace' = @(
            "Skipping caching composite resource '$dscResourceTypeName'."
            "Composite resources aren't supported in DSCv3."
        ) -join ' '
    } | ConvertTo-Json -Compress
    $host.ui.WriteErrorLine($trace)
    continue
}

[!NOTE] Out of scope for this issue, but the trace messages from the adapter all use the Debug level, when they should use the appropriate level for their message, and many of them lack sufficient context for a typical user to understand which resource the message is referring to and what the message indicates.

anmenaga commented 1 month ago

After #435 this issue happens only in Win-PS adapter; In PS6+ PS Adapter this is fixed.