Skip to content

Commit d335be1

Browse files
authored
Add error message for failure to install after choosing not to trust repository (#712)
1 parent 30ff560 commit d335be1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/code/InstallHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private List<PSResourceInfo> ProcessRepositories(
155155

156156
var findHelper = new FindHelper(_cancellationToken, _cmdletPassedIn);
157157
List<PSResourceInfo> allPkgsInstalled = new List<PSResourceInfo>();
158+
bool sourceTrusted = true;
158159

159160
foreach (var repo in listOfRepositories)
160161
{
@@ -166,7 +167,6 @@ private List<PSResourceInfo> ProcessRepositories(
166167

167168
// Source is only trusted if it's set at the repository level to be trusted, -TrustRepository flag is true, -Force flag is true
168169
// OR the user issues trust interactively via console.
169-
var sourceTrusted = true;
170170
if (repo.Trusted == false && !trustRepository && !_force)
171171
{
172172
_cmdletPassedIn.WriteVerbose("Checking if untrusted repository should be used");
@@ -246,9 +246,9 @@ private List<PSResourceInfo> ProcessRepositories(
246246
// At this only package names left were those which could not be found in registered repositories
247247
foreach (string pkgName in _pkgNamesToInstall)
248248
{
249-
var message = String.Format("Package '{0}' with requested version range {1} could not be installed as it was not found in any registered repositories",
250-
pkgName,
251-
_versionRange.ToString());
249+
string message = !sourceTrusted ? $"Package '{pkgName}' with requested version range '{_versionRange.ToString()}' could not be found in any trusted repositories" :
250+
$"Package '{pkgName}' with requested version range '{_versionRange.ToString()}' could not be installed as it was not found in any registered repositories";
251+
252252
var ex = new ArgumentException(message);
253253
var ResourceNotFoundError = new ErrorRecord(ex, "ResourceNotFoundError", ErrorCategory.ObjectNotFound, null);
254254
_cmdletPassedIn.WriteError(ResourceNotFoundError);

0 commit comments

Comments
 (0)