Skip to content

Commit a993f08

Browse files
Improve Get-PnPPlannerPlan error message (#4500)
Improve Get-PnPPlannerPlan error message when no plan with the specified name is found Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent fe9f941 commit a993f08

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Commands/Base/PipeBinds/PlannerPlanPipeBind.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ public PlannerPlan GetPlan(Cmdlet cmdlet, PnPConnection connection, string acces
4141
if (plans != null && plans.Any())
4242
{
4343
var collection = plans.Where(p => p.Title.Equals(_id));
44-
if (collection != null && collection.Any() && collection.Count() == 1)
44+
var plansCount = collection.Count();
45+
if (plansCount == 1)
4546
{
4647
return collection.First();
4748
}
49+
else if (plansCount == 0)
50+
{
51+
throw new PSArgumentException($"No plan with the title '{_id}' found. Use Get-PnPPlannerPlan to list all plans.");
52+
}
4853
else
4954
{
50-
throw new PSArgumentException("More than one plan with the same title found. Use Get-PnPPlannerPlan to list all plans.");
55+
throw new PSArgumentException($"Found {plansCount} plans with the same title '{_id}'. Use Get-PnPPlannerPlan to list all plans.");
5156
}
5257
}
5358
}

0 commit comments

Comments
 (0)