PnP-PowerShell icon indicating copy to clipboard operation
PnP-PowerShell copied to clipboard

Add-PnpListItem does not bubble up exceptions

Open kliemohn opened this issue 9 years ago • 4 comments

Reporting an Issue or Missing Feature

Add-PnpListItem reports an error in the output such as "Invalid Text Value", but if I put a try/catch around Add-PnpListItem, it does not go into the catch block.

Expected behavior

The error should be thrown to me so I can catch it.

Actual behavior

I see error output, but cannot catch it.

Steps to reproduce behavior

Add a list item with more than 255 characters to a single line text field. Put a try/catch around Add-PnpListItem. The error is shown to the user, but does not go into the catch block.

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

  • [ ] PnP PowerShell for SharePoint 2013
  • [ ] PnP PowerShell for SharePoint 2016
  • [x] PnP PowerShell for SharePoint Online

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

2.17.17...

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub
  • [x] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means

kliemohn avatar Sep 12 '17 16:09 kliemohn

I experience the same problem with "Apply-PnPProvisioningTemplate"

ghost avatar May 16 '18 14:05 ghost

This is a workaround i found in another thread. Save the result as a variable (and suppress the error) and check if the variable is null. It doesn't throw an exception error when you see the message hence why the catch doesn't work and this is by design so your scripts can carry on running. Hope this helps, it resolved it for me. Thank you @erwinvanhunen

$termgroupcheck = Get-PnPTermGroup -Identity "$termgroup" -ErrorAction SilentlyContinue

if($termgroupcheck -eq $null) { Write-Host "$termgroupcheck doesn't exist" } else { Write-Host "$termgroupcheck does exist" }

CloudDesignBox avatar Jun 01 '18 15:06 CloudDesignBox

You could use the Get-PnPException cmdlet for this. https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/get-pnpexception?view=sharepoint-ps

dsanatelli avatar May 02 '19 15:05 dsanatelli

We have the same issue with Set-PnPListItem.

lafe avatar Aug 24 '20 07:08 lafe