powershell icon indicating copy to clipboard operation
powershell copied to clipboard

Add improved error handling for CSPConfig limit errors in Add-PnPApp and Publish-PnPApp

Open Copilot opened this issue 5 months ago • 2 comments

  • [x] Explored repository structure and located relevant files
  • [x] Built project successfully to verify baseline
  • [x] Implement CSPConfig error detection and improved error handling in AddApp.cs
  • [x] Implement CSPConfig error detection and improved error handling in PublishApp.cs
  • [x] Test the changes (build succeeded)
  • [x] Address code review feedback
    • Wrapped cleanup operation in try-catch to prevent masking original error
    • Changed from generic Exception to InvalidOperationException for semantic clarity
    • Refined cleanup exception handling to catch only ServerException and ClientRequestException
  • [x] Final validation and build verification complete
  • [x] Added changelog entry referencing PR #5120

All changes implemented and tested successfully!

Original prompt

This section details on the original issue you should resolve

<issue_title>Failed to deploy SPFx with PS Add-PnPApp - getting error Value of: [CSPConfig] cannot exceed: [100000]</issue_title> <issue_description>It's not possible to deploy an SPFx to the site collection App catalog when the number of Trusted Script Sources in Content Security Policy is too large (in our case, it was 582). It doesn't work with Add-PnPApp (Add-PnPApp -Path ./myapp.sppkg -Scope Site -Publish) or with ALM PnP. => The app is added to the Site Collection App Catalog, but the status remains Deployed = No. The error is - "Value of: [CSPConfig] cannot exceed: [100000]."

I would expect that command to work well in the scope of site collection. It should not take into account script sources from other site collections. (Trusted Script Sources on tenant level)

I'm using Windows operating system with PSVersion 7.5.3 and PnP.PowerShell 3.1.0 version.

Please check also related issues - https://github.com/SharePoint/sp-dev-docs/issues/10412, https://github.com/SharePoint/sp-dev-docs/issues/10369

</issue_description>

<agent_instructions>Can you try fixing this?</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes pnp/powershell#5112


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Oct 17 '25 08:10 Copilot

@copilot Add a changelog entry referencing PR #5120

KoenZomers avatar Oct 17 '25 13:10 KoenZomers

@copilot Add a changelog entry referencing PR #5120

Added changelog entry in commit 6f1b8dd

Copilot avatar Oct 17 '25 13:10 Copilot