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

Microsoft.DSC/PowerShell resource or config file size limit #640

Open
3 tasks done
cdhunt opened this issue Feb 11, 2025 · 2 comments
Open
3 tasks done

Microsoft.DSC/PowerShell resource or config file size limit #640

cdhunt opened this issue Feb 11, 2025 · 2 comments
Assignees
Labels
Issue-Bug Something isn't working Need-Review
Milestone

Comments

@cdhunt
Copy link

cdhunt commented Feb 11, 2025

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • 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 cdhunt added Issue-Bug Something isn't working Need-Review labels Feb 11, 2025
@Gijsreyn
Copy link
Contributor

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.

@SteveL-MSFT
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Need-Review
Projects
None yet
Development

No branches or pull requests

3 participants