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

Oh My Posh is unable to download and store the latest version #1498

Closed
1 task done
hjkta opened this issue Dec 24, 2021 · 37 comments
Closed
1 task done

Oh My Posh is unable to download and store the latest version #1498

hjkta opened this issue Dec 24, 2021 · 37 comments
Assignees
Labels
🤔 info needed Further information is requested 💤 stale

Comments

@hjkta
Copy link

hjkta commented Dec 24, 2021

Code of Conduct

  • I agree to follow this project's Code of Conduct

What happened?

After Install-Module oh-my-posh -Scope CurrentUser and then Import-Module oh-my-posh in my ps config I get this error. Have no idea what should I do to fix that.
image

Theme

This happens even before using the theme.

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

No logs due to "Write-PoshDebug: The term 'Write-PoshDebug' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
@hjkta hjkta added the 🐛 bug Something isn't working label Dec 24, 2021
@JanDeDobbeleer
Copy link
Owner

@hjkta weird, you should be able to install in that case. Unless something else fails in the process, we do swallow the error in the assumption it's that specific use case. Where are your modules stored?

@hjkta
Copy link
Author

hjkta commented Dec 24, 2021

Here you are
image

@hjkta
Copy link
Author

hjkta commented Dec 24, 2021

Also I can give some more information. I just uninstall it and install again, open new tab in my terminal and got this:
image

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Dec 24, 2021

@hjkta that makes more sense now, we've seen that before but my mind is a blank, let's see how we can fix that.

@JanDeDobbeleer
Copy link
Owner

@hjkta found it, in other cases this was due to character encoding and the following did resolve it:

[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
Import-Module oh-my-posh

@hjkta
Copy link
Author

hjkta commented Dec 24, 2021

Unfortunately it didn't help. I've add these lines to my config:
image
But I still get the same errors.
Also, nothing has changed after reinstalling module :(

@JanDeDobbeleer
Copy link
Owner

@hjkta can you try again and run Get-Error directly after it happens? That should show that issue at hand.

@CollinChaffin
Copy link

Same error for me unable to download. Removing and reinstalling the module still results in the error downloading the binary.

@CollinChaffin
Copy link

Info: it appears it is now downloading to the wrong directory, placing it's binary in the module root of: C:\Program Files\WindowsPowerShell\Modules\oh-my-posh and not C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\6.41.0 like it should. Probably why the themes then fail. Does this help?

λ Import-Module oh-my-posh
Downloading oh-my-posh executable for 6.41.0
Downloading oh-my-posh themes for 6.41.0
C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\6.41.0\oh-my-posh.psm1 : Oh
My Posh is unable to download and store the latest version.
In case you installed using AllUsers and are a non-admin user,
please run the following command as an administrator:
Import-Module oh-my-posh
At line:1 char:1

  • Import-Module oh-my-posh
  •   + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,oh-
     my-posh.psm1
    
    

@CollinChaffin
Copy link

The "Get-PoshCommand" is not correct:

return "$((Get-Item $MyInvocation.MyCommand.ScriptBlock.Module.ModuleBase).Parent.FullName)/oh-my-posh$extension"

does not take into account that the module resides in a subdir under "oh-my-posh" of the version number. This causes the one executable of "oh-my-posh.exe" to get dumped into the root folder not the module folder, and this erroneous path is then stored in $executable and throws off the other downloads.

@CollinChaffin
Copy link

CollinChaffin commented Dec 26, 2021

FOUR bugs:

First bug line 83, typo on tmp$ remove the erroneous dollar sign on the replace:

$tmp = New-TemporaryFile | Rename-Item -NewName { $_ -replace 'tmp$', 'zip' } -PassThru


Second bug:

Expand-Archive does not have a param called DestinationPath, it's OutputPath


Third bug:

You used a forwardslash on line 2 "/themes" should be "\themes"


Fourth bug:

Destination "themes" does not exist and you are not creating it


When I fix these four things and TEST it, it works.

@JanDeDobbeleer
Copy link
Owner

@CollinChaffin you have no idea how much the CAPS almost made me throw my phone out of the window. You act as if we do not test this, I run this on different machines and shells every day, even during holidays so next time, show some respect.

Yes, we install this in the root folder. By design. A lot of users reported the executable took up a lot of space thus we decided to store it one time only. That's not an issue, it just works.

Forward or backward slashes don't matter for Powershell on Windows, it just works, so that can't also be the issue.

What is the issue is that you have another module installed that's overwriting the built in Expand-Archive functionality. See here. That's the only bug here. So not FOUR different issues as if I'm the biggest idiot on this planet.

@hjkta you might also want to validate if you have the same issue due to having Pscx installed.

@CollinChaffin
Copy link

CollinChaffin commented Dec 27, 2021

No offense but the caps were simply to draw attention to testing it. If you did, I am curious what system you tested on where 'tmp$' isn't a showstopping syntax error? You're right, the slash technically isn't an issue but the expand-archive param differs in 5.x vs 7.x but I ran it on both and the dollar sign in 'tmp' causes a terminating failure on all off them which is why I ask. Also expand-archive will not create the destination folder 'themes' in 5.x as shown here:

 C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\6.41.0  
λ  $tmp | Expand-Archive -OutputPath $destination -Force
Expand-Archive : Expand-Archive's OutputPath parameter has an invalid path of
'C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\6.41.0/themes': The path
'C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\6.41.0\themes' supplied for
OutputPath must exist.
At line:1 char:8
+ $tmp | Expand-Archive -OutputPath $destination -Force
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (OutputPath:String) [Expand-Archive]
   , PSArgumentException
    + FullyQualifiedErrorId : NotExist,Pscx.Commands.IO.Compression.ExpandArchiveCo
   mmand



 C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\6.41.0  
λ  mkdir $destination

    Directory:  C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\6.41.0

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d-----       12/26/2021   4:11 PM        1   themes


 C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\6.41.0  
λ  $tmp | Expand-Archive -OutputPath $destination -Force

(SUCCESSFUL UNZIP)

And for the record, I've been coding 34 yrs had someone simply capitalized the word TEST I would have laughed at myself and felt like an idiot and apologized for releasing it that way, not jumped down their throat. In hindsight, I should have put a smiley emoji next to it as it was just meant for you to slap your forehead. :)

@hjkta
Copy link
Author

hjkta commented Dec 27, 2021

@JanDeDobbeleer this is result for Get-Error:

Exception             :
    Type    : Microsoft.PowerShell.Commands.WriteErrorException
    Message : Oh My Posh is unable to download and store the latest version.
In case you installed using AllUsers and are a non-admin user,
please run the following command as an administrator:

Import-Module oh-my-posh
    HResult : -2146233087
CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,oh-my-posh.psm1
InvocationInfo        :
    MyCommand        : oh-my-posh.psm1
    ScriptLineNumber : 19
    OffsetInLine     : 1
    HistoryId        : 1
    ScriptName       : C:\Users\<username>\.config\powershell\user_profile.ps1
    Line             : Import-Module oh-my-posh

    PositionMessage  : At C:\Users\<username>\.config\powershell\user_profile.ps1:19 char:1
                       + Import-Module oh-my-posh
                       + ~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\<username>\.config\powershell
    PSCommandPath    : C:\Users\<username>\.config\powershell\user_profile.ps1
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, C:\Users\<username>\Documents\PowerShell\Modules\oh-my-posh\6.39.0\oh-my-posh.psm1: line 128
                        at <ScriptBlock>, C:\Users\<username>\.config\powershell\user_profile.ps1: line 19
                        at <ScriptBlock>, C:\Users\<username>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1: line 1
                        at <ScriptBlock>, <No file>: line 1

@CollinChaffin Actually this error happens only on my work PC, I also have the same module on my home PC installed under PowerShell\Modules and all fine. I don't think, to be honest, that's the reason.

Also I don't have Pscx. Should I install it?

@JanDeDobbeleer
Copy link
Owner

@hjkta no, definitely not 😁 Thanks for this one, let's see if we can get to the bottom of this. A less general catch block might be useful to print the actual error.

@JanDeDobbeleer
Copy link
Owner

For anyone following along, this is both PowerShell Core (7.2.1) and Powershell 5 (5.1.22000.282)

image

But, yes. I never test this apparently...

@JanDeDobbeleer
Copy link
Owner

@hjkta I pushed an update that should print the original error, that should show us what the issue is.

@hjkta
Copy link
Author

hjkta commented Dec 27, 2021

@JanDeDobbeleer I tried to reinstall, this error is gone, but the first one still exists:

Oh My Posh is unable to download and store the latest version. In case you installed using AllUsers and are a
     | non-admin user, please run the following command as an administrator:  Import-Module oh-my-posh

@JanDeDobbeleer
Copy link
Owner

@hjkta give it a moment, I don't think it's through just yet 😅

@JanDeDobbeleer
Copy link
Owner

@hjkta you should be able to install 6.41.1 now

@hjkta
Copy link
Author

hjkta commented Dec 27, 2021

Oh My Posh is unable to download and store the latest version.
In case you installed using AllUsers and are a non-admin user,
please run the following command as an administrator:

Import-Module oh-my-posh

Original Error:

Program 'oh-my-posh.exe' failed to run: StandardOutputEncoding is only supported when standard output is redirected.At C:\Users\<username>\Documents\PowerShell\Modules\oh-my-posh\6.41.1\oh-my-posh.psm1:106 char:20
+     $poshVersion = & $executable --version
+                    ~~~~~~~~~~~~~~~~~~~~~~~.
Set-PoshPrompt: C:\Users\<username>\.config\powershell\user_profile.ps1:20
Line |
  20 |  Set-PoshPrompt -Theme amro
     |  ~~~~~~~~~~~~~~
     | The term 'Set-PoshPrompt' is not recognized as a name of a cmdlet, function, script file, or executable program.
     | Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

@JanDeDobbeleer
Copy link
Owner

@hjkta this is still the same issue as other experienced with a non UTF-8 pwsh setup. The latest version also sets the encoding right for the module, if that doesn't fix I suggest to take a look at this post and force your entire Windows setup to UTF-8.

@hjkta
Copy link
Author

hjkta commented Dec 28, 2021

Unfortunately it didn't help. I tried both options and no result for me.

@DEberhardt
Copy link

Have the same. If it helps, I have tried with v6.42.4 and v5.19.1 - both displayed this.
Reverting back to 3.133.0 for now.

the bin and themes folders could not be downloaded, the PSM1 and PSD1 file did.
Might be my security software intervening, but I am not allowed to test/disable on my work PC (on my home PC I am on the newest version)

PowerShell Version Table

Name                           Value
----                           -----
PSVersion                      5.1.19041.1320
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1320
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PowerShell Host

Name             : ConsoleHost
Version          : 5.1.19041.1320
InstanceId       : 49733c8f-c1ec-471f-b15d-800288dff3ed
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-GB
CurrentUICulture : en-GB
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Installed NET Frameworks



PSChildName                      Version        Release
-----------                      -------        -------
v2.0.50727                       2.0.50727.4927
v3.0                             3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation  3.0.6920.4902
v3.5                             3.5.30729.4926
Client                           4.8.04084      528372
Full                             4.8.04084      528372
Client                           4.0.0.0

I can try updating to 4.0 and 5.0 respectively to see where it starts, if that helps

@JanDeDobbeleer
Copy link
Owner

@DEberhardt staying on 3 isn't advised, it's a bit old. You can always install via Winget/Scoop, that will always work. Probably it's indeed a security setting, there's so much strange things happening with modules I'm close to dropping that installation method in favor of Winget/Scoop.

@JanDeDobbeleer
Copy link
Owner

I think I know why this happens. Controlled Folder Action will disallow access to Documents. As this probably is a company security setting we can't work around this. I'll try to find which folders are open to write to.

@wuranxu
Copy link

wuranxu commented Jan 13, 2022

I think I know why this happens. Controlled Folder Action will disallow access to Documents. As this probably is a company security setting we can't work around this. I'll try to find which folders are open to write to.

maybe, I can't import oh-my-posh in my company's pc.There is some limits for folder permission(write).So can you change or support it.I work sadly because of using default windows terminal without oh-my-posh!!! 😞

D:\Users\rx.wu> Get-Module oh-my-posh
D:\Users\rx.wu> Import-Module oh-my-posh
Downloading oh-my-posh executable for 6.41.1
Oh My Posh is unable to download and store the latest version.
In case you installed using AllUsers and are a non-admin user,
please run the following command as an administrator:


Line |
   4 |  Set-PoshPrompt -Theme JanDeDobbeleer
     |  ~~~~~~~~~~~~~~
     | The term 'Set-PoshPrompt' is not recognized as a name of a cmdlet, function, script file, or
     | executable program. Check the spelling of the name, or if a path was included, verify that the path is
     | correct and try again.

@JanDeDobbeleer
Copy link
Owner

This one's on my list to try to fix this evening.

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Jan 14, 2022

So, to reduce the overhead which a module introduces (as it always did include too many cross platform binaries) everything is now stored inside $HOME/.oh-my-posh. This implies you can install with scope allusers and it will still work too as it everything is downloaded per user if the executable isn't there. This also fixes all permission issues. Now, I did test this on my machine with these settings enabled (and was able to reproduce) which is why this is only marked as relates to. Looking for feedback before considering this as resolved.

@JanDeDobbeleer JanDeDobbeleer added 🤔 info needed Further information is requested and removed 🐛 bug Something isn't working labels Jan 15, 2022
@hjkta
Copy link
Author

hjkta commented Jan 17, 2022

So, I tried and got this:
image

I also have [console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new() in my config file.

Should I install oh-my-posh with AllUsers? I use CurrentUser now.

@JanDeDobbeleer
Copy link
Owner

@hjkta I feel this is all connected to policies rather than anything we can still do from oh-my-posh. I'll try to reproduce, but it's been very challenging so far.

@DEberhardt
Copy link

Hello,

can confirm that it downloaded fine today on my work machine - v6.51.0 - Thank you!

@stale
Copy link

stale bot commented Jan 24, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the 💤 stale label Jan 24, 2022
@stale stale bot closed this as completed Feb 2, 2022
@nkasco
Copy link

nkasco commented Feb 23, 2022

This might need to be a new issue but there should really be an option for those in corporate environments. Having a module downloaded and then it immediately goes and downloads another exe would not make my security team happy.

This was never an issue in older versions, but I'm now setting this up on a new machine. What changed?

@JanDeDobbeleer
Copy link
Owner

@nkasco this was by user request as due to PowerShell's nature it always keeps older versions as well resulting in a lot of storage overhead. This way, the PowerShell module is also only a wrapper around the executable. In case this is an issue in corporate environments, please move to winget/scoop as an alternative or add the binary manually to your system and PATH.

@nkasco
Copy link

nkasco commented Feb 23, 2022

@JanDeDobbeleer Thanks for the response, in my case only downloads from PS Gallery are open. Everything else gets auto-blocked by the proxy. I suspect this might be the case for some others in corporate environments.

Copy link

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤔 info needed Further information is requested 💤 stale
Projects
None yet
Development

No branches or pull requests

6 participants