jdx/mise

Disable error message when `Remove-Item` target does not exist in pwsh

Closed this issue · 0 comments

NavyD commented

Describe the bug

Using Remove-Item to remove non-existing environment variables in powershell displays an error message, e.g. trying to remove a non-existing variable when using mise deactivate will result in an error message

# mise deactivate
Remove-Item: 
Line |
   7 |  Remove-Item -Path Env:/__MISE_WATCH
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path 'Env:\__MISE_WATCH' because it does not exist.

To Reproduce

Invoke-Expression (& { (mise activate pwsh | Out-String) })
mise deactivate

Expected behavior

This type of error message should be avoided by using Remove-Item -ErrorAction SilentlyContinue -Path xxx consistent with the unset behavior in bash/zsh

mise doctor output

n/a

Additional context