-
Notifications
You must be signed in to change notification settings - Fork 464
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
Powershell one-line install on Windows 11 error - "You cannot call a method on a null-valued expression" #3749
Comments
FWIW I get the same error in Powershell on my Windows 10 machine. Assigned issue to our expert :) |
@pmolodo Would you mind downloading the script to a local file and running that to see if a more descriptive error message is output? We test the install script via GitHub Actions, which should at least approximate a fresh Windows install, so I'm not sure at the moment what the problem is exactly. I'll try to trigger the workflow tomorrow and see if it's also stopped working. I can't reproduce this with either a local copy of the script or the remote command: ❯ .\install.ps1
found version 2.48.0 for latest/windows/amd64
installed C:\Users\User\bin\chezmoi.exe ❯ iex "&{$(irm 'https://get.chezmoi.io/ps1')}"
found version 2.48.0 for latest/windows/amd64
installed C:\Users\User\bin\chezmoi.exe The error message can suggest a fault with a code, but the local script still works for me even if I set strict mode to version 3 (currently the most strict). I also don't get any errors out of PSScriptAnalyzer. |
Disclaimer: I know nothing about Windows. I tried the following:
|
@twpayne That makes two of us. I don't know how to proceed here given that I only have my own environment available to me. I don't think I do anything outlandish with my PowerShell/Windows setup. At the moment, it isn't clear to me if this is caused by a script error or some relatively new Windows change. You may also recall how extensively we tested the changes I made to the script, and nothing like this came up then. The error message also gives no hints. Would you or @pmolodo be willing to step through the script in a debugger and see where it fails? I'm particularly interested in if it fails to run completely, or perhaps if it fails on a web request which means a variable is null when it shouldn't be, etc. I used VS Code with the PowerShell extension when writing the new script in my chezmoi fork. Here is the {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "install.ps1",
"type": "PowerShell",
"request": "launch",
"script": "${workspaceFolder}/assets/scripts/install.ps1",
"cwd": "${cwd}",
"args": ["-d", "doctor"]
},
]
} I will open a PR tomorrow to make the workflow run again and see where that leads. |
Fortunately for me, and unfortunately for debugging, it worked when I
downloaded it separately and then executed it. It only failed when I tried
via the invoke expression
I did confirm that all the bits before the invoke expression call seemed to
be working - ie, it printed out what seemed to be the contents of the
script.
…On Thu, May 2, 2024, 6:16 PM bradenhilton ***@***.***> wrote:
@twpayne <https://github.com/twpayne> That makes two of us.
I don't know how to proceed here given that I only have my own environment
available to me. I don't think I do anything outlandish with my
PowerShell/Windows setup. At the moment, it isn't clear to me if this is
caused by a script error or some relatively new Windows change. You may
also recall how extensively we tested the changes I made to the script, and
nothing like this came up then.
The error message also gives no hints. Would you or @pmolodo
<https://github.com/pmolodo> be willing to step through the script in a
debugger and see where it fails? I'm particularly interested in if it fails
to run completely, or perhaps if it fails on a web request which means a
variable is null when it shouldn't be, etc.
I used VS Code with the PowerShell extension
<https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell>
when writing the new script in my chezmoi fork. Here is the launch.json
configuration I used, unchanged:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "install.ps1",
"type": "PowerShell",
"request": "launch",
"script": "${workspaceFolder}/assets/scripts/install.ps1",
"cwd": "${cwd}",
"args": ["-d", "doctor"]
},
]
}
I will open a PR tomorrow to make the workflow run again and see where
that leads.
—
Reply to this email directly, view it on GitHub
<#3749 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAARQ6G37JLB7OPMFZBEWPTZALQM7AVCNFSM6AAAAABHERCNZCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJRHE4TIMRXGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
The workflow ran successfully with strict mode both disabled and enabled. I'm not smart (or stupid) enough to say with 100% certainty that the script is not at fault, but I am starting to think this may be a Windows issue that could be resolved with one or more pre-install steps being added to the docs, I just don't know what they are yet. I thought about perhaps messing around with a Windows image. |
What's your execution policy, out of curiosity?
…On Fri, May 3, 2024, 3:03 PM bradenhilton ***@***.***> wrote:
The workflow ran successfully with strict mode both disabled
<https://github.com/twpayne/chezmoi/actions/runs/8939819608/job/24556616884#step:4:32>
and enabled
<https://github.com/twpayne/chezmoi/actions/runs/8939892930/job/24556832891#step:4:32>
.
I'm not smart (or stupid) enough to say with 100% certainty that the
script is not at fault, but I am starting to think this may be a Windows
issue that could be resolved with one or more pre-install steps being added
to the docs, I just don't know what they are yet. I thought about perhaps
messing around with a Windows image.
—
Reply to this email directly, view it on GitHub
<#3749 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAARQ6FMXHJHF6REVGLV7ZTZAQCUVAVCNFSM6AAAAABHERCNZCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJTHAYTSNZVHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I use ❯ $PSVersionTable.PSVersion
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 4 2
❯ Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine RemoteSigned ❯ $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 22621 2506
❯ Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine Undefined |
OK, it seems I have PowerShell 5.1 on my Windows 10 machine which is missing the
|
@twpayne Thanks for looking into this. The Windows PowerShell build is usually updated when Windows is updated. The build number in your output indicates that you are using build 19041 of Windows 10, which was released in May of 2020. Would you mind providing the output of the following commands from PowerShell?
Here is my output for all commands: ❯ $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 22621 2506 ❯ [System.Runtime.InteropServices.RuntimeInformation] | Get-Member -Static
TypeName: System.Runtime.InteropServices.RuntimeInformation
Name MemberType Definition
---- ---------- ----------
Equals Method static bool Equals(System.Object objA, System.Object objB)
IsOSPlatform Method static bool IsOSPlatform(System.Runtime.InteropServices.OSPlatform osPlatform)
ReferenceEquals Method static bool ReferenceEquals(System.Object objA, System.Object objB)
FrameworkDescription Property static string FrameworkDescription {get;}
OSArchitecture Property static System.Runtime.InteropServices.Architecture OSArchitecture {get;}
OSDescription Property static string OSDescription {get;}
ProcessArchitecture Property static System.Runtime.InteropServices.Architecture ProcessArchitecture {get;} ❯ Get-CimInstance -Class Win32_OperatingSystem | Get-Member -MemberType Property
TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_OperatingSystem
Name MemberType Definition
---- ---------- ----------
...
OSArchitecture Property string OSArchitecture {get;}
... There are a few more ways to determine bitness, I'll look into them. |
Here you go. For reference, I installed Windows 10 around December 2022 but have kept it up to date with Windows Update. I've been unable to update it since January 2024 due to this Windows bug. I'll re-install the system at some point, but I'll wait until we've resolved this so we don't lose the machine that reproduces the problem :)
|
@twpayne I think you and @pmolodo are experiencing two different issues. I believe you are unable to run the script at all due to I'm slightly confused, as I ran the installers again with A simple fix for your issue would be to rearrange the function such that it checks the edition of PowerShell and simply uses CIM on Windows PowerShell (the "Desktop" edition). |
Small update: I can now reproduce this in a Windows Docker container: ❯ docker run -it mcr.microsoft.com/windows:ltsc2019
Microsoft Windows [Version 10.0.17763.5696]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\>powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\> iex "&{$(irm 'https://get.chezmoi.io/ps1')}"
You cannot call a method on a null-valued expression.
At line:1 char:1
+ &{<#
+ ~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull The modifications I made to the script in #3751 appear to work as expected: PS C:\> iex "&{$(irm 'https://raw.githubusercontent.com/twpayne/chezmoi/33087eeeffa1f8347c16387a6e96a366919105c3/assets/scripts/install.ps1')}"
found version 2.48.0 for latest/windows/amd64
installed C:\bin\chezmoi.exe |
Thank you very much! |
Describe the bug
I did a fresh install of Windows 11, and one of the first things I did on it was try to install chezmoi.
I followed the install docs to install via a Powershell one liner, and ran this:
iex "&{$(irm 'https://get.chezmoi.io/ps1')}"
Unfortunately, it returned this error:
To reproduce
See above. I was on a fresh install but it was a company managed Windows 11, so it's not at completely generic / stock settings.
Expected behavior
Chezmoi should download + install.
The text was updated successfully, but these errors were encountered: