Merge pull request #327 from Icinga:fix/initial_import_exception

Fix: Possible exception on first import run

On certain systems you can run into an exception on the first run of the system, as the module is imported but the cache is written on this import run. Therefor a second import run is required, to import the newly generated files.
This commit is contained in:
Lord Hepipud 2021-08-17 09:44:19 +02:00 committed by GitHub
commit a52e30190b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View file

@ -16,6 +16,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#311](https://github.com/Icinga/icinga-powershell-framework/issues/311) Fixes an issue with negative inputs on some scenarios which will cause an exception for checks instead of continuing executing them properly
* [#317](https://github.com/Icinga/icinga-powershell-framework/pull/317) Fixes certain file names being too long, causing errors on deploying branches
* [#326](https://github.com/Icinga/icinga-powershell-framework/pull/326) Fixes import for module files, by using the full path to the module now instead of the name only, as files could be placed inside a folder which is not listed inside the `$ENV:PSModulePath`
* [#327](https://github.com/Icinga/icinga-powershell-framework/pull/327) Fixes possible exception on first import run for certain systems
### Enhancements

View file

@ -18,6 +18,10 @@ function Use-Icinga()
);
if ($null -ne $Global:Icinga -And $Global:Icinga.ContainsKey('RebuildCache') -And $Global:Icinga.RebuildCache) {
# On some systems, this call will re-build the cache
Import-Module (Join-Path -Path (Get-IcingaForWindowsRootPath) -ChildPath 'icinga-powershell-framework') -Global -Force;
# The second run would then actually import the new module. Only happens on some systems, but with this we fix
# possible exceptions
Import-Module (Join-Path -Path (Get-IcingaForWindowsRootPath) -ChildPath 'icinga-powershell-framework') -Global -Force;
}