Skip to content

cChocoPackageInstall can fail if run immediately after Chocolatey is installed. Invalid Path #174

@rcarpenter79

Description

@rcarpenter79

Checklist

  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my problem.
  • I have verified this is not an issue for a specific package.
  • I have verified this issue is not security related.

What You Are Seeing?

When I ran this resource on a server that was freshly built I was seeing errors about invalid paths.

I looked at the code and traced the problem to the functions Get-ChocoInstalledPackage and Get-ChocoVersion.

The problem was caused by the environment variable $env:ChocolateyInstall being null.
I could retrieve the requried value using [environment]::GetEnvironmentVariable('ChocolateyInstall', 'Machine').

This problem was intermittent. I think it depended on the order that DSC ran the resources, as several steps caused the server I was building to reboot. I think a reboot after installing Chocolatey avoids this issue.

What is Expected?

The code should check if the environment variables haven't been initialised yet and update them if they haven't.

Adding this to the start of both functions resolves the problem.

if ([string]::IsNullOrEmpty($env:ChocolateyInstall))
{
    $env:ChocolateyInstall = [environment]::GetEnvironmentVariable('ChocolateyInstall', 'Machine')
}

How Did You Get This To Happen?

This problem happened when installing Chocolatey and then trying to install a package immediately afterwards.

System Details

  • Operating System: 10.0.20348.0
  • Windows PowerShell version: 5.1.20348.1366
  • Chocolatey CLI Version: 1.3.1
  • Chocolatey Licensed Extension version: N/A
  • Chocolatey License type: Community
  • Terminal/Emulator: PowerShell

Installed Packages

chocolatey 1.3.1
chocolatey-compatibility.extension 1.0.0
chocolatey-core.extension 1.4.0
notepadplusplus 8.5.2
notepadplusplus.install 8.5.2

Output Log

I don't have the error in the log file. 
I rebuilt the server using a modified local copy of the cChoco module to test my change.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIssues where something has happened which was not expected or intended.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions