Skip to content

Install-PSResource unuititive error when module is already installed #1272

@ThomasNieto

Description

@ThomasNieto

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

If you try to install a module that is already installed it will write an error that is quite ambigious for the user referencing Object reference not set to an instance of an object. error instead of saying that it is already installed. It does also throw a invalid operation exception.

Expected behavior

# errors saying module is already installed

Actual behavior

Install-PSResource pester

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its Trusted value by
running the Set-PSResourceRepository cmdlet. Are you sure you want to install the PSResource from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
Install-PSResource: Unable to successfully install package 'Pester': 'Object reference not set to an instance of an object.'
Install-PSResource: Operation is not valid due to the current state of the object.

Error details

Exception             :
    Type    : System.InvalidOperationException
    Message : Operation is not valid due to the current state of the object.
    HResult : -2146233079
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper
CategoryInfo          : InvalidOperation: (Microsoft.PowerShel…dlets.InstallHelper:InstallHelper) [Install-PSResource],
 InvalidOperationException
FullyQualifiedErrorId : InstallPackageTryMoveContentFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResourc
e
InvocationInfo        :
    MyCommand        : Install-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 29
    Line             : Install-PSResource pester
    PositionMessage  : At line:1 char:1
                       + Install-PSResource pester
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Install-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :



Install-PSResource: Unable to successfully install package 'Pester': 'Object reference not set to an instance of an object.'
PS /mnt/c/Users/Thomas/Documents/github/apt> $error[1] | Get-Error

Exception             :
    Type           : System.Management.Automation.PSInvalidOperationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Unable to successfully install package 'Pester': 'Object reference not set to an instance of an o
bject.'
            HResult : -2146233087
        CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : InvalidOperation
    Message        : Unable to successfully install package 'Pester': 'Object reference not set to an instance of an ob
ject.'
    InnerException :
        Type       : System.NullReferenceException
        TargetSite :
            Name          : TryMoveInstallContent
            DeclaringType : Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper, Microsoft.PowerShell.PSResourceGe
t, Version=0.5.22.0, Culture=neutral, PublicKeyToken=null
            MemberType    : Method
            Module        : Microsoft.PowerShell.PSResourceGet.dll
        Message    : Object reference not set to an instance of an object.
        Source     : Microsoft.PowerShell.PSResourceGet
        HResult    : -2147467261
        StackTrace :
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallHelper.TryMoveInstallContent(String tempInstallPath, ScopeType
scope, Hashtable packagesHash)
    HResult        : -2146233079
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
CategoryInfo          : InvalidOperation: (Microsoft.PowerShel…s.InstallPSResource:InstallPSResource) [Install-PSResour
ce], PSInvalidOperationException
FullyQualifiedErrorId : InstallPackageFailed,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
InvocationInfo        :
    MyCommand        : Install-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 29
    Line             : Install-PSResource pester
    PositionMessage  : At line:1 char:1
                       + Install-PSResource pester
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Install-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

beta22

Visuals

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions