DSC icon indicating copy to clipboard operation
DSC copied to clipboard

Microsoft.DSC/PowerShell resource or config file size limit

Open cdhunt opened this issue 10 months ago • 2 comments

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 have a configuration with a collection of Microsoft.DSC/PowerShell/Microsoft.WinGet.DSC/WinGetPackage. With 15 resources I get an error. With 14 it reliably works. It doesn't matter what parameters are in the 15th.

Steps to reproduce

dsc config get -f C:\Users\chunt\desktop.dsc.yml

Config and trace output: https://gist.github.com/cdhunt/48ccd50d822da6a8bf24e8b50f8272fc

Expected behavior

Expect to get a results collection.

Actual behavior

`ERROR dsc::subcommand: 68: Command: Resource 'pwsh' [exit code 1] manifest description: Error`

Error details

`ERROR dsc::subcommand: 68: Command: Resource 'pwsh' [exit code 1] manifest description: Error`

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
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

3.0.0-rc.1

Visuals

No response

cdhunt avatar Feb 11 '25 20:02 cdhunt

Interesting @cdhunt. I don't think it has particular have to do with the fact how many resources you've defined. Instead, it's the underlying modules installed that breaks the script.

Basically, if you follow the breadcrumbs on the adapter that's executing it, the lookup table that's being built, probably will contain 14 cache resource for you (for me it was 13).

Looking at the error message, I think the checking that happens might be incorrect, but this is an assumption. @SteveL-MSFT or @anmenaga, changing the code in the powershell.resource.ps1 from this:

# only need to cache the resources that are used
$dscResourceModules = $desiredState | ForEach-Object { $_.Type.Split('/')[0] }
if ($null -eq $dscResourceModules) {
    $trace = @{'Debug' = 'ERROR: Could not get list of DSC resource types from provided JSON.' } | ConvertTo-Json -Compress
    $host.ui.WriteErrorLine($trace)
    exit 1
}

$dscResourceCache = Invoke-DscCacheRefresh -module $dscResourceModules
if ($dscResourceCache.count -lt $dscResourceModules.count) {
    $trace = @{'Debug' = 'ERROR: DSC resource module not found.' } | ConvertTo-Json -Compress
    $host.ui.WriteErrorLine($trace)
    exit 1
}

To:

# only need to cache the resources that are used
$dscResourceModules = $desiredState | ForEach-Object { $_.Type.Split('/')[0] }
$moduleInput = $desiredState | Select-Object -ExpandProperty Type | Sort-Object -Unique
if ($null -eq $dscResourceModules) {
    $trace = @{'Debug' = 'ERROR: Could not get list of DSC resource types from provided JSON.' } | ConvertTo-Json -Compress
    $host.ui.WriteErrorLine($trace)
    exit 1
}

$dscResourceCache = Invoke-DscCacheRefresh -module $dscResourceModules
$moduleInput | Foreach-Object {
  if ($dscResourceCache.Type -notcontains $_) {
    $trace = @{'Debug' = 'ERROR: DSC resource module not found.' } | ConvertTo-Json -Compress
    $host.ui.WriteErrorLine($trace)
    exit 1
  }
}

Does the validation that was being looked for I guess. If you want me to hit up a PR on it, just let me know.

Gijsreyn avatar Feb 12 '25 05:02 Gijsreyn

@Gijsreyn can you create a PR and also a test? Thanks!

SteveL-MSFT avatar Feb 18 '25 01:02 SteveL-MSFT