Powershell: Start-DevPowerShell always throws an InvalidOperation error on exit

Created on 17 Jul 2020  路  6Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

> Start-DevPowerShell
>> exit

Expected behavior

<exits quietly like a good shell>

Actual behavior

> exit
PS C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShell> exit
InvalidOperation: C:\Users\Robert Holt\Documents\Dev\Microsoft\PowerShell\build.psm1:1973
Line |
1973 |          if ($ZapDisable) {
     |              ~~~~~~~~~~~
     | The variable '$ZapDisable' cannot be retrieved because it has not been set.

Area-Maintainers-Build First-Time-Issue Issue-Bug Resolution-Fixed Up-for-Grabs

Most helpful comment

Probably the if statement just needs to be swapped to if (Get-Variable -Name ZapDisable -ValueOnly -ErrorAction SilentlyContinue) { ... }

IMO though strict mode is rarely useful and I'm not really sure why we have it enabled in the first place.

All 6 comments

I would like to tackle this (seems pretty straightforward) but I am a first-timer so bear with me. What is considered standard when checking for variables that could be null in the powershell community? StrictMode is set to version 3.0 so it seems like checking for this variable in most cases would throw an error (since it is never initialized by Start-DevPowerShell). Should this if statement be removed? Or perhaps should should StrictMode be set to Off before this if statement?

Probably the if statement just needs to be swapped to if (Get-Variable -Name ZapDisable -ValueOnly -ErrorAction SilentlyContinue) { ... }

IMO though strict mode is rarely useful and I'm not really sure why we have it enabled in the first place.

Thank you vexx. Idk what the etiquette is here since you basically wrote the solution. Should I make a change or would you like to do it?

Idk what the etiquette is here since you basically wrote the solution. Should I make a change or would you like to do it?

I think @vexx32 is just trying to point you in the right direction. You already expressed the desire to open a PR for this (and there's more overhead in doing that), so I'd say you're free to proceed.

Yep, pretty much ^^

Also, while I'm _pretty_ sure that'll work just fine, there's always a chance more will be needed there, I haven't tested it. 馃榿

:tada:This issue was addressed in #13350, which has now been successfully released as v7.1.0-preview.7.:tada:

Handy links:

Was this page helpful?
0 / 5 - 0 ratings