Skip to content

Commit 708a860

Browse files
authored
Merge pull request #2414 from AdmiringWorm/2412-Faling-to-load-all-helper-cmdlets-when-extensions-fails-to-load
(#2412) Change importing of Licensed extension to output warning
2 parents b288cd1 + a9b0ea9 commit 708a860

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/chocolatey.resources/helpers/chocolateyInstaller.psm1

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,24 @@ if (Test-Path $extensionsPath) {
6262
Write-Debug "Importing '$licensedExtensionPath'"
6363
Write-Debug "Loading 'chocolatey.licensed' extension"
6464

65-
# Attempt to import module via already-loaded assembly
66-
$licensedAssembly = $currentAssemblies |
67-
Where-Object { $_.GetName().Name -eq 'chocolatey.licensed' } |
68-
Select-Object -First 1
69-
70-
if ($licensedAssembly) {
71-
# It's already loaded, just import the existing assembly as a module for PowerShell to use
72-
Import-Module $licensedAssembly
65+
try {
66+
# Attempt to import module via already-loaded assembly
67+
$licensedAssembly = $currentAssemblies |
68+
Where-Object { $_.GetName().Name -eq 'chocolatey.licensed' } |
69+
Select-Object -First 1
70+
71+
if ($licensedAssembly) {
72+
# It's already loaded, just import the existing assembly as a module for PowerShell to use
73+
Import-Module $licensedAssembly
74+
}
75+
else {
76+
# Fallback: load the extension DLL from the path directly.
77+
Import-Module $licensedExtensionPath
78+
}
7379
}
74-
else {
75-
# Fallback: load the extension DLL from the path directly.
76-
Import-Module $licensedExtensionPath
80+
catch {
81+
# Only write a warning if the Licensed extension failed to load in some way.
82+
Write-Warning "Import failed for Chocolatey Licensed Extension. Error: '$_'"
7783
}
7884
}
7985

0 commit comments

Comments
 (0)