Skip to content

Save-PSResource: Improve error message when passing bad package name that looks like a filename #1901

@helpimnotdrowning

Description

@helpimnotdrowning

Summary of the new feature / enhancement

I was mistakenly running the command

Save-PSResource ./Sisk.HttpServer -Path ./test`

and getting confused when I would get the error

Save-PSResource: Object reference not set to an instance of an object.

I was thinking that this was a bug where Save-PSResource was not able to find the path I was passing, but only after lots of "troubleshooting" did I realize that I prepended my package name with "./" - the error message is not helpful.

This specific error only seems to occur when the package name looks like a path, ex. ./PackageName or /PackageName. It is not due to some invalid characters in the package name, running Save-PSResource Sisk./HttpServer correctly tries to search all of my repositories before writing

Save-PSResource: Package(s) 'Sisk./HttpServer' could not be installed from registered repositories 'NuGetGallery, PSGallery'.

Additionally, with this error it stops searching after the first repository.


With -Verbose:

Save-PSResource /Sisk.HttpServer -Version 1.5.2 -Path . -TrustRepository -Verbose -Repository NuGetGallery 
VERBOSE: Attempting to search for packages in 'NuGetGallery'
WARNING: Installing dependencies is not currently supported for V3 server protocol repositories. The package will be installed without installing dependencies.
VERBOSE: Performing the operation "Save-PSResource" on target "Package to save: 'Sisk.HttpServer', version: '1.5.2'".
VERBOSE: Performing the operation "Save-PSResource" on target "Package to install: 'Sisk.HttpServer', version: '1.5.2'".
VERBOSE: This resource is not a PowerShell package and will be installed to the modules path: .
Save-PSResource: Object reference not set to an instance of an object.
VERBOSE: Attempting to delete '/tmp/35ba3d33-4c54-4f1e-a56e-9d38b6a0788d'
VERBOSE: Successfully deleted '/tmp/35ba3d33-4c54-4f1e-a56e-9d38b6a0788d'
Save-PSResource: Object reference not set to an instance of an object.

Proposed technical implementation details (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions