-
Notifications
You must be signed in to change notification settings - Fork 113
Exception using Start-Polaris when PowerShell strict mode is enabled. #201
Description
Polaris Bug Report
Description of the bug
When PowerShell's strict mode is enabled the Start-Polaris command throws the following exception:
The variable '$Script:ClassDefinitions' cannot be retrieved because it has not been set.
At C:\Program Files\WindowsPowerShell\Modules\Polaris\0.2.0\lib\Polaris.Class.ps1:15 char:33Steps to reproduce
Steps to reproduce the behavior:
Import-Module PolarisSet-StrictMode -Version LatestStart-Polaris- See error.
Expected behavior
Polaris should not throw exceptions in strict mode - at least when these are not related to the Polaris module itself. Using PowerShell's strict mode is good practice for identifying bugs and scripting issues that can otherwise by difficult and time consuming to track down
Verbose output of the script
There is no additional information obtained by setting the Verbose preference. The exception is thrown before any Write-Verbose statements are encountered.
Additional context
The issue is caused by the following line, within the parameter declarations, in Polaris.Class.ps1:
[string]$ClassDefinitions = $Script:ClassDefinitions$Script:ClassDefinitions is undefined at the time the parameter declaration is encountered, and therefore in strict mode, this will throw an exception.
It is possible to workaround this issue by using the following script line before calling Start-Polaris:
$Script:ClassDefinitions = [string]::EmptyHaving declared the variable, strict mode will no longer cause the command to throw an exception.
Not sure why the parameter in the reference script uses an undeclared variable as a default value. I would suggest a quick fix would be to declare the variable early in the execution lifecycle of the module, perhaps in the .psm1 file, before any command that relies on its value can be invoked.
Version Information
Polaris 0.2.0
| Name | Version |
|---|---|
| Polaris | 0.2.0 |
| PSVersion | PSEdition | PSCompatibleVersions | BuildVersion | CLRVersion | WSManStackVersion | PSRemotingProtocolVersion | SerializationVersion |
|---|---|---|---|---|---|---|---|
| 5.1.18362.145 | Desktop | 1.0.-1.-1, 2.0.-1.-1, 3.0.-1.-1, 4.0.-1.-1, 5.0.-1.-1, 5.1.18362.145 | 10.0.18362.145 | 4.0.30319.42000 | 3.0 | 2.3 | 1.1.0.1 |