Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2651 fail quietly when removing a non-existing variable #2696

Closed
wants to merge 1 commit into from

Conversation

phreed
Copy link

@phreed phreed commented Jul 21, 2023

This was discussed in issue #2651

When Powershell starts it runs the $PROFILE script.
micromamba init updates these profiles (e.g. $profile.CurrentUserAllHosts) with something like the following:

#region mamba initialize
# !! Contents within this block are managed by 'mamba shell init' !!
$Env:MAMBA_ROOT_PREFIX = "C:\Users\me\micromamba"
$Env:MAMBA_EXE = "C:\Users\me\.bin\micromamba.exe"
(& $Env:MAMBA_EXE 'shell' 'hook' -s 'powershell' -p $Env:MAMBA_ROOT_PREFIX) | Out-String | Invoke-Expression
#endregion

When run the following error is produced.

Remove-Variable:
Line |
   3 |  Remove-Variable MambaModuleArgs
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find a variable with the name 'MambaModuleArgs'.

The cause of the error is revealed by running the following command.

(& $Env:MAMBA_EXE 'shell' 'hook' -s 'powershell' -p $Env:MAMBA_ROOT_PREFIX) | Out-String

Which produces:

Import-Module "$Env:MAMBA_ROOT_PREFIX\condabin\Mamba.psm1" -ArgumentList $MambaModuleArgs
Remove-Variable MambaModuleArgs

While Mamba.psm1 accepts a missing/empty ArgumentList, the subsequent Remove-Variable on the undefined variable MambaModuleArgs produces the error.

I suspect the idea is that MambaModuleArgs is presumed to be set outside of the region mamba initialize. Therefore, I think the fix should accommodate that inten by changing the powershell shell hook...

Remove-Variable -Name MambaModuleArgs -ErrorAction SilentlyContinue

A related issue is that the documentation is weak on the purpose for MambaModuleArgs.

It is used in Mamba.psm1 and where seems to only have one defined entry.

$MambaModuleArgs = @{"ChangePs1"=$True};

Copy link
Member

@AntoinePrv AntoinePrv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AntoinePrv
Copy link
Member

@phreed I am failing to push to this PR, cold you rebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants