pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
985 stars 665 forks source link

[BUG] Get-PnPTerm throws misleading error if term not found #3037

Open sympmarc opened 3 years ago

sympmarc commented 3 years ago

Reporting an Issue or Missing Feature

When I call Get-PnPTerm with a value which is not in the Term Set like so:

Get-PnPTerm -TermGroup $termGroup -TermSet $termSet -Identity $splitValues[$i] -Recursive

I get the following error:

Get-PnPTerm : Value cannot be null.
Parameter name: clientObject
At line:1 char:1
+ Get-PnPTerm -TermGroup $termGroup -TermSet $termSet -Identity $splitV ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-PnPTerm], ArgumentNullException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Taxonomy.GetTerm

This is misleading, as the values I'm passing in are not null. @ToddKlindt and I looked at them carefully. (Trust, but verify!)

Expected behavior

I expect to get a null term back, but not an error.

Actual behavior

See error above.

I expect the issue is in parsing the response from core. When I remove -Recursive the error is a little different:

Get-PnPTerm : Specified argument was out of the range of valid values.
Parameter name: index
At line:1 char:1
+ Get-PnPTerm -TermGroup $termGroup -TermSet $termSet -Identity $splitV ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-PnPTerm], ServerException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Taxonomy.GetTerm

If I use -ErrorAction SilentlyContinue I can supress the error, but I don't think I should need to.

Steps to reproduce behavior

Call Get-PnPTerm with any TermSet using an -Identity which is not present.

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

3.28.2012

How did you install the PnP-PowerShell Cmdlets?