Add-Member : Cannot bind argument to parameter 'InputObject' because it is null.
r15ch13 opened this issue Β· comments
#16 has introduced a new problem with:
Line 344 in 14079ad
Both checks return false
and we get:
PS C:\Users\appveyor> .\install.ps1 -RunAsAdmin
Initializing...
Downloading...
Extracting...
Creating shim...
- Add-Member : Cannot bind argument to parameter 'InputObject' because it is null.
- At C:\Users\appveyor\install.ps1:357 char:28
- + ... oopConfig | Add-Member -MemberType NoteProperty -Name $Name -Value $V ...
- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- + CategoryInfo : InvalidData: (:) [Add-Member], - ParameterBindingValidationException
- + FullyQualifiedErrorId : - ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand
Maybe we should apply the fix to line 328:
return @(Get-Content $SCOOP_CONFIG_FILE -Raw | ConvertFrom-Json -ErrorAction Stop)
instead of line 342:
$scoopConfig = @(Use-Config)
@r15ch13 can you test it? /cc @MarkMichaelis
I can't even reproduce the error from #15. The code used in Core is still the same and works.
What I find strange, is the error message @MarkMichaelis posted was caused by line 404
I can't even reproduce the error from #15. The code used in Core is still the same and works.
Have you tweaked Set-StrictMode -Version Latest
? Set strict mode and the error will occur in PS5.
Okay, that was not mentioned π
Set-StrictMode -Version Latest
# powershell 5
("{}" | ConvertFrom-Json -ErrorAction Stop).Count
# The property 'Count' cannot be found on this object. Verify that the property exists.
# At line:1 char:1
# + ("{}" | ConvertFrom-Json -ErrorAction Stop).Count
# + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# + CategoryInfo : NotSpecified: (:) [], PropertyNotFoundException
# + FullyQualifiedErrorId : PropertyNotFoundStrict
# powershell 6+
("{}" | ConvertFrom-Json -ErrorAction Stop).Count
# 1
I guess .Count
makes no sense anyway because it will always return 1.
/Edit: Nice, it was me who added this check ScoopInstaller/Scoop@630ba04
I should probably enable StrictMode on my system for testing. π
Disabling StrictMode is the default setting in PowerShell and it's easier for developers to develop scripts, however, some users have StrictMode enabled in their computers.
I think we should force StrictMode to a value in the installer script.
I guess we could change the check to
if ($scoopConfig -isnot [System.Management.Automation.PSObject]) {
Enforcing StrictMode for the installer should be possible.
For Scoop itself it would require a rewrite π
A special case, assuming the content of config.json is [1,2]
:
("[1,2]" | ConvertFrom-Json) -isnot [System.Management.Automation.PSObject]
# True in PowerShell 6+
("[1,2]" | ConvertFrom-Json) -isnot [System.Management.Automation.PSObject]
# False in PowerShell 5. Damn it! It will escape from the if condition flow
$scoopConfig = ("[1,2]" | ConvertFrom-Json)
$scoopConfig | Add-Member -MemberType NoteProperty -Name "debug" -Value "true"
$scoopConfig | ConvertTo-Json
#[
# {
# "value": 1,
# "debug": "true"
# },
# {
# "value": 2,
# "debug": "true"
# }
#]
# <---- causing unexpected behavior. π
Although I don't think any user would like to edit and save config.json with an array([1,2]
).
/edit: patch diff https://github.com/ScoopInstaller/Install/compare/h404bi-patch-1?expand=1