You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
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:33
Steps to reproduce
Steps to reproduce the behavior:
Import-Module Polaris
Set-StrictMode -Version Latest
Start-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:
$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]::Empty
Having 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.
Polaris Bug Report
Description of the bug
When PowerShell's strict mode is enabled the Start-Polaris command throws the following exception:
Steps to reproduce
Steps to reproduce the behavior:
Import-Module Polaris
Set-StrictMode -Version Latest
Start-Polaris
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
:$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
:Having 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
The text was updated successfully, but these errors were encountered: