Skip to content

Add error message for failure to install after choosing not to trust repository #712

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

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/code/FindPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
/// </summary>
[Cmdlet(VerbsCommon.Find,
"PSResource",
DefaultParameterSetName = ResourceNameParameterSet,
SupportsShouldProcess = true)]
DefaultParameterSetName = ResourceNameParameterSet)]
[OutputType(typeof(PSResourceInfo), typeof(PSCommandResourceInfo))]
public sealed class FindPSResource : PSCmdlet
{
Expand Down
8 changes: 4 additions & 4 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private List<PSResourceInfo> ProcessRepositories(

var findHelper = new FindHelper(_cancellationToken, _cmdletPassedIn);
List<PSResourceInfo> allPkgsInstalled = new List<PSResourceInfo>();
bool sourceTrusted = true;

foreach (var repo in listOfRepositories)
{
Expand All @@ -168,7 +169,6 @@ private List<PSResourceInfo> ProcessRepositories(

// Source is only trusted if it's set at the repository level to be trusted, -TrustRepository flag is true, -Force flag is true
// OR the user issues trust interactively via console.
var sourceTrusted = true;
if (repo.Trusted == false && !trustRepository && !_force)
{
_cmdletPassedIn.WriteVerbose("Checking if untrusted repository should be used");
Expand Down Expand Up @@ -249,9 +249,9 @@ private List<PSResourceInfo> ProcessRepositories(
// At this only package names left were those which could not be found in registered repositories
foreach (string pkgName in _pkgNamesToInstall)
{
var message = String.Format("Package '{0}' with requested version range {1} could not be installed as it was not found in any registered repositories",
pkgName,
_versionRange.ToString());
string message = !sourceTrusted ? $"Package '{pkgName}' with requested version range '{_versionRange.ToString()}' could not be found in any trusted repositories" :
$"Package '{pkgName}' with requested version range '{_versionRange.ToString()}' could not be installed as it was not found in any registered repositories";

var ex = new ArgumentException(message);
var ResourceNotFoundError = new ErrorRecord(ex, "ResourceNotFoundError", ErrorCategory.ObjectNotFound, null);
_cmdletPassedIn.WriteError(ResourceNotFoundError);
Expand Down