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

DSC Compliance Failed: Cannot find path C:\\choco\\cache\\ChocoInstalled.xml\ because it does not exist. #160

Open
DevonBritton opened this issue Aug 2, 2021 · 7 comments

Comments

@DevonBritton
Copy link

Hi there.

Recently the DSC process which had been running smoothly began failing due to the below error:

Error message
The PowerShell DSC resource '[cChocoPackageInstaller]installAndroidStudio' with SourceInfo '::660::9::cChocoPackageInstaller' threw one or more non-terminating errors while running the Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
More details
[cChocoPackageInstaller]installAndroidStudio
Resource instance error
{
    "Exception":  {
                      "Message":  "The PowerShell DSC resource \u0027[cChocoPackageInstaller]installAndroidStudio\u0027 with SourceInfo \u0027::660::9::cChocoPackageInstaller\u0027 threw one or more non-terminating errors while running the Set-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.",
                      "Data":  {

                               },
                      "InnerException":  {
                                             "ErrorRecord":  "Cannot find path \u0027C:\\choco\\cache\\ChocoInstalled.xml\u0027 because it does not exist.",
                                             "ItemName":  "C:\\choco\\cache\\ChocoInstalled.xml",
                                             "SessionStateCategory":  4,
                                             "WasThrownFromThrowStatement":  false,
                                             "Message":  "Cannot find path \u0027C:\\choco\\cache\\ChocoInstalled.xml\u0027 because it does not exist.",
                                             "Data":  "System.Collections.ListDictionaryInternal",
                                             "InnerException":  null,
                                             "TargetSite":  "System.Collections.ObjectModel.Collection`1[System.String] ExpandMshGlobPath(System.String, Boolean, System.Management.Automation.PSDriveInfo, System.Management.Automation.Provider.ContainerCmdletProvider, System.Management.Automation.CmdletProviderContext)",
                                             "StackTrace":  "   at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider provider, CmdletProviderContext context)\r\n   at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider\u0026 providerInstance)\r\n   at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider\u0026 providerInstance)\r\n   at Microsoft.PowerShell.Commands.RemoveItemCommand.ProcessRecord()",
                                             "HelpLink":  null,
                                             "Source":  "System.Management.Automation",
                                             "HResult":  -2146233087
                                         },
                      "TargetSite":  null,
                      "StackTrace":  null,
                      "HelpLink":  null,
                      "Source":  null,
                      "HResult":  -2146233079
                  },
    "TargetObject":  null,
    "CategoryInfo":  {
                         "Category":  7,
                         "Activity":  "",
                         "Reason":  "InvalidOperationException",
                         "TargetName":  "",
                         "TargetType":  ""
                     },
    "FullyQualifiedErrorId":  "NonTerminatingErrorFromProvider",
    "ErrorDetails":  null,
    "InvocationInfo":  null,
    "ScriptStackTrace":  null,
    "PipelineIterationInfo":  [

                              ]
}

I have seen that the "chocoinstalled.xml" file is being created in the correct location, but then deleted before the DSC process is completed causing it to fail. I've also noticed that the step that's failing is taking longer than the previous steps to run and I'm not sure if that might be the issue?

Any assistance would be appreciated.

Kind Regards,
Devon Britton.

@Hans-v-M
Copy link

I am seeying the exact same behaviour, during uninstall the chocoinstalled.xml is removed, and 1~3 seconds after the dsc state fails the file is recreated.

@JeffreyH1989
Copy link

Hello,

We are encountering the same issue when upgrading OpenJDK. Partial contained 11.0.8.1 before. When set to 11.0.14.1, the upgrade process runs succesfully (installer exits 0). However a second later we receive the same missing XML error

@pauby
Copy link
Member

pauby commented May 16, 2022

We need steps to reproduce this before it can be looked at, including sample code.

@jberezanski
Copy link

jberezanski commented Oct 3, 2022

I just encountered the same error when upgrading the pnpm package from version 7.11.0 to 7.13.0. Here is the relevant part of Start-DscConfiguration output:

2022-10-03T18:29:25.2480640Z output Chocolatey v1.1.0 Uninstalling the following packages: pnpm  pnpm v7.11.0  Skipping auto uninstaller - No registry snapshot.  pnpm 
2022-10-03T18:29:25.2482539Z has been successfully uninstalled.  Chocolatey uninstalled 1/1 packages.   See the log for details 
2022-10-03T18:29:25.2484323Z (C:\ProgramData\chocolatey\logs\chocolatey.log).
2022-10-03T18:29:25.2504410Z VERBOSE: [BLDSVR003]:                            [[cChocoPackageInstaller]pnpm::[mChocolateyPackages]ChocoPackages] Re-Installing pnpm with
2022-10-03T18:29:25.2507807Z  correct version 7.13.0
2022-10-03T18:29:25.2613140Z VERBOSE: [BLDSVR003]:                            [[cChocoPackageInstaller]pnpm::[mChocolateyPackages]ChocoPackages] Install command: 'choco
2022-10-03T18:29:25.2615986Z  install pnpm -y --version="7.13.0" --no-progress'
2022-10-03T18:29:42.0063254Z VERBOSE: [BLDSVR003]:                            [[cChocoPackageInstaller]pnpm::[mChocolateyPackages]ChocoPackages] Package output 
2022-10-03T18:29:42.0065037Z Chocolatey v1.1.0 Installing the following packages: pnpm By installing, you accept licenses for the packages.  pnpm v7.13.0 pnpm package 
2022-10-03T18:29:42.0067494Z files install completed. Performing other installation steps. Downloading pnpm    from 
2022-10-03T18:29:42.0068632Z 'https://github.com/pnpm/pnpm/releases/download/v7.13.0/pnpm-win-x64.exe'  Download of pnpm.exe (40.6 MB) completed. Hashes match. 
2022-10-03T18:29:42.0071268Z C:\ProgramData\chocolatey\lib\pnpm\tools\pnpm.exe  ShimGen has successfully created a shim for pnpm.exe  The install of pnpm was 
2022-10-03T18:29:42.0072502Z successful.   Software install location not explicitly set, it could be in package or   default install location of installer.  Chocolatey 
2022-10-03T18:29:42.0074960Z installed 1/1 packages.   See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
2022-10-03T18:29:42.3851997Z Cannot find path 'C:\ProgramData\chocolatey\cache\ChocoInstalled.xml' because it does not exist.
2022-10-03T18:29:42.3863645Z     + CategoryInfo          : ObjectNotFound: (C:\ProgramData\...coInstalled.xml:) [], CimException
2022-10-03T18:29:42.3866598Z     + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
2022-10-03T18:29:42.3869360Z     + PSComputerName        : BLDSVR003.mycompany.com
2022-10-03T18:29:42.3872158Z  
2022-10-03T18:29:42.3897464Z VERBOSE: [BLDSVR003]: LCM:  [ End    Set      ]  [[cChocoPackageInstaller]pnpm::[mChocolateyPackages]ChocoPackages]  in 25.1310 seconds.
2022-10-03T18:29:42.4014463Z The PowerShell DSC resource '[cChocoPackageInstaller]pnpm::[mChocolateyPackages]ChocoPackages' with SourceInfo '::2::2::cChocoPackageInstal
2022-10-03T18:29:42.4017618Z ler' threw one or more non-terminating errors while running the Set-TargetResource functionality. These errors are logged to the ETW channe
2022-10-03T18:29:42.4020597Z l called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.

Here is the configuration fragment:

cChocoPackageInstall pnpm
{
    Name = 'pnpm'
    Ensure = 'Present'
    Version = '7.13.0'    # the error happens when upgrading from a previous version
}

We are specifying the exact pnpm package version (using the Version property on the cChocoPackageInstaller resource), so the resource uninstalls the previous version and installs the specified one (instead of doing it in one go via "choco upgrade"). The new package version installs successfully, but the resource encounters an error.

The culprit seems to be this line in cChocoPackageInstall.psm1:

        Remove-Item $ChocoInstallList -Force

This will fail if the file does not exist (and the function does not check for it). When Version is specified, the resource calls UninstallPackage (which deletes the file) and InstallPackage (which attempts to delete the file again).
The fix would be to either add an existence check (but that would still not be 100% reliable due to race conditions) or simply -ErrorAction SilentlyContinue.

@General-Fault
Copy link

This happens when the resource is called with the Version parameter set, but a different version is already installed.

See cChocoPackageInstall.psm1 - Set-TargetResource
The ChocoInstalled.xml cache file is created at the beginning of Set-TargetResource by a call to IsPackageInstalled (line 97).
If the result is true and "Version" is specified, it is assumed that the incorrect version is installed (Test-TargetResource would have returned false), so Set-TargetResource calls UninstallPackage, which deletes the ChocoInstalled.xml file. Then InstallPackage is called, which again tries, and fails, to delete the ChocoInstalled.xml file again.

Steps to Reproduce:

choco install notepadplusplus --version=8.5.8

Invoke-DscResource -ModuleName 'cChoco' -Name 'cChocoPackageInstaller' -Method 'Set' -Property @{
  Name='notepadplusplus'
  Version='8.6.5'
  Ensure='Present'
} -Verbose

If instead, you use MinimumVersion, the package is upgraded instead of being uninstalled/installed. Of course, this has the side effect of not downgrading packages if that is the desire.

Invoke-DscResource -ModuleName 'cChoco' -Name 'cChocoPackageInstaller' -Method 'Set' -Property @{
  Name='notepadplusplus'
  MinimumVersion='8.6.5'
  Ensure='Present'
} -Verbose

@JeffreyH89
Copy link

Hi,

Any update regarding this issue? This is still happening. We've added retries to prevent failing pipelines.

Thank you

@pauby
Copy link
Member

pauby commented Jul 2, 2024

There is no update on this at the moment. For transparency we have not prioritised this issue.

If this is an issue for you, have you looked at the Chocolatey DSC resource?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants