Skip to content

Commit cd54aa4

Browse files
alericksonanamnavi
authored andcommitted
Add some error handling (PowerShell#861)
1 parent cf552d0 commit cd54aa4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/code/FindHelper.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,19 @@ public List<PSResourceInfo> FindTag(
255255
return foundPackages;
256256
}
257257

258-
// Error out if repository array of names to be searched contains wildcards.
259258
if (repository != null)
260259
{
261260
repository = Utils.ProcessNameWildcards(repository, removeWildcardEntries:false, out string[] errorMsgs, out _repositoryNameContainsWildcard);
261+
262+
if (string.Equals(repository[0], '*'))
263+
{
264+
_cmdletPassedIn.ThrowTerminatingError(new ErrorRecord(
265+
new PSArgumentException ("-Repository parameter does not support entry '*'."),
266+
"RepositoryDoesNotSupportWildcardEntry",
267+
ErrorCategory.InvalidArgument,
268+
this));
269+
}
270+
262271
foreach (string error in errorMsgs)
263272
{
264273
_cmdletPassedIn.WriteError(new ErrorRecord(
@@ -274,6 +283,15 @@ public List<PSResourceInfo> FindTag(
274283
try
275284
{
276285
repositoriesToSearch = RepositorySettings.Read(repository, out string[] errorList);
286+
if (repository != null && repositoriesToSearch.Count == 0)
287+
{
288+
_cmdletPassedIn.ThrowTerminatingError(new ErrorRecord(
289+
new PSArgumentException ("Cannot resolve -Repository name. Run 'Get-PSResourceRepository' to view all registered repositories."),
290+
"RepositoryNameIsNotResolved",
291+
ErrorCategory.InvalidArgument,
292+
this));
293+
}
294+
277295
foreach (string error in errorList)
278296
{
279297
_cmdletPassedIn.WriteError(new ErrorRecord(

0 commit comments

Comments
 (0)