From f2ec97e6463a40d01795c989cee2b20b023c397d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 08:57:16 +0000 Subject: [PATCH 1/5] Initial plan From 79919adfcdb44651073e7459bdeb346c58031aa0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 09:04:48 +0000 Subject: [PATCH 2/5] Add CSPConfig error handling for Add-PnPApp and Publish-PnPApp cmdlets Co-authored-by: KoenZomers <5940670+KoenZomers@users.noreply.github.com> --- src/Commands/Apps/AddApp.cs | 21 +++++++++++++++++++++ src/Commands/Apps/PublishApp.cs | 24 +++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Commands/Apps/AddApp.cs b/src/Commands/Apps/AddApp.cs index 372351be3..344684209 100644 --- a/src/Commands/Apps/AddApp.cs +++ b/src/Commands/Apps/AddApp.cs @@ -121,6 +121,27 @@ private void AddPnPApp() } WriteObject(result); } + catch (ServerException ex) when (ex.Message.Contains("CSPConfig") && ex.Message.Contains("100000")) + { + // Handle the specific CSPConfig error when deploying to site collection app catalog + // This is a known SharePoint service-side limitation where tenant-level script sources + // are incorrectly included in site-level CSP validation + manager.Remove(result, Scope); + + var errorMessage = "Failed to deploy the app due to a SharePoint limitation. " + + "The error 'Value of: [CSPConfig] cannot exceed: [100000]' occurs when there are too many " + + "Trusted Script Sources configured at the tenant level, and SharePoint incorrectly includes " + + "them when validating site collection app catalog deployments.\n\n" + + "Workarounds:\n" + + "1. Add the app without publishing (remove the -Publish parameter) and manually publish it later through the SharePoint UI.\n" + + "2. Reduce the number of Trusted Script Sources at the tenant level.\n" + + "3. Contact Microsoft Support to request a fix for this service-side issue.\n\n" + + "For more information, see:\n" + + "- https://github.com/SharePoint/sp-dev-docs/issues/10412\n" + + "- https://github.com/SharePoint/sp-dev-docs/issues/10369"; + + throw new Exception(errorMessage, ex); + } catch { // Exception occurred rolling back diff --git a/src/Commands/Apps/PublishApp.cs b/src/Commands/Apps/PublishApp.cs index 6a27c7ffe..e8e4d6086 100644 --- a/src/Commands/Apps/PublishApp.cs +++ b/src/Commands/Apps/PublishApp.cs @@ -91,7 +91,29 @@ private void PublishPnPApp() var app = Identity.GetAppMetadata(ClientContext, Scope); if (app != null) { - manager.Deploy(app, SkipFeatureDeployment, Scope); + try + { + manager.Deploy(app, SkipFeatureDeployment, Scope); + } + catch (ServerException ex) when (ex.Message.Contains("CSPConfig") && ex.Message.Contains("100000")) + { + // Handle the specific CSPConfig error when deploying to site collection app catalog + // This is a known SharePoint service-side limitation where tenant-level script sources + // are incorrectly included in site-level CSP validation + var errorMessage = "Failed to publish the app due to a SharePoint limitation. " + + "The error 'Value of: [CSPConfig] cannot exceed: [100000]' occurs when there are too many " + + "Trusted Script Sources configured at the tenant level, and SharePoint incorrectly includes " + + "them when validating site collection app catalog deployments.\n\n" + + "Workarounds:\n" + + "1. Manually publish the app through the SharePoint UI (navigate to Site Contents > App Catalog).\n" + + "2. Reduce the number of Trusted Script Sources at the tenant level.\n" + + "3. Contact Microsoft Support to request a fix for this service-side issue.\n\n" + + "For more information, see:\n" + + "- https://github.com/SharePoint/sp-dev-docs/issues/10412\n" + + "- https://github.com/SharePoint/sp-dev-docs/issues/10369"; + + throw new Exception(errorMessage, ex); + } } else { From 35f61efd267d427da2e8aa784139bbdb8d824de5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 09:07:08 +0000 Subject: [PATCH 3/5] Address code review feedback: wrap cleanup in try-catch and use InvalidOperationException Co-authored-by: KoenZomers <5940670+KoenZomers@users.noreply.github.com> --- src/Commands/Apps/AddApp.cs | 11 +++++++++-- src/Commands/Apps/PublishApp.cs | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Commands/Apps/AddApp.cs b/src/Commands/Apps/AddApp.cs index 344684209..169f879f8 100644 --- a/src/Commands/Apps/AddApp.cs +++ b/src/Commands/Apps/AddApp.cs @@ -126,7 +126,14 @@ private void AddPnPApp() // Handle the specific CSPConfig error when deploying to site collection app catalog // This is a known SharePoint service-side limitation where tenant-level script sources // are incorrectly included in site-level CSP validation - manager.Remove(result, Scope); + try + { + manager.Remove(result, Scope); + } + catch + { + // If cleanup fails, continue to throw the original error message + } var errorMessage = "Failed to deploy the app due to a SharePoint limitation. " + "The error 'Value of: [CSPConfig] cannot exceed: [100000]' occurs when there are too many " + @@ -140,7 +147,7 @@ private void AddPnPApp() "- https://github.com/SharePoint/sp-dev-docs/issues/10412\n" + "- https://github.com/SharePoint/sp-dev-docs/issues/10369"; - throw new Exception(errorMessage, ex); + throw new InvalidOperationException(errorMessage, ex); } catch { diff --git a/src/Commands/Apps/PublishApp.cs b/src/Commands/Apps/PublishApp.cs index e8e4d6086..5ca9fd9ef 100644 --- a/src/Commands/Apps/PublishApp.cs +++ b/src/Commands/Apps/PublishApp.cs @@ -112,7 +112,7 @@ private void PublishPnPApp() "- https://github.com/SharePoint/sp-dev-docs/issues/10412\n" + "- https://github.com/SharePoint/sp-dev-docs/issues/10369"; - throw new Exception(errorMessage, ex); + throw new InvalidOperationException(errorMessage, ex); } } else From 2ddbe0e8af24ffb5cbd78cbc7e057ed6c523467b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 09:08:53 +0000 Subject: [PATCH 4/5] Refine exception handling in cleanup to catch only specific exceptions Co-authored-by: KoenZomers <5940670+KoenZomers@users.noreply.github.com> --- src/Commands/Apps/AddApp.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Commands/Apps/AddApp.cs b/src/Commands/Apps/AddApp.cs index 169f879f8..91dc21943 100644 --- a/src/Commands/Apps/AddApp.cs +++ b/src/Commands/Apps/AddApp.cs @@ -130,7 +130,11 @@ private void AddPnPApp() { manager.Remove(result, Scope); } - catch + catch (ServerException) + { + // If cleanup fails, continue to throw the original error message + } + catch (ClientRequestException) { // If cleanup fails, continue to throw the original error message } From db2a4d8d31d5b7a87d8e8e5abd360c74357469de Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 17 Oct 2025 13:04:26 +0000 Subject: [PATCH 5/5] Add changelog entry for PR #5120 Co-authored-by: KoenZomers <5940670+KoenZomers@users.noreply.github.com> --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24193bd02..09744c597 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fix `Get-PnPTenantRestrictedSearchMode` throwing an error in some cases [#5042](https://github.com/pnp/powershell/pull/5042) - Fixed issues with `Get-PnPTenantInfo`, `Set-PnPList`, `Remove-PnPSiteSensitivityLabel`, `Set-PnPSiteSensitivityLabel`, `Send-PnPMail` and `Set-PnPWebHeader` cmdlets returning an error [#5059](https://github.com/pnp/powershell/pull/5059) - Fixed issue with `Get-PnPChangelog -Nightly` throwing an error [#5070](https://github.com/pnp/powershell/pull/5070) +- Improved error handling in `Add-PnPApp` and `Publish-PnPApp` cmdlets to provide clearer messages when encountering CSPConfig limit errors during site collection app catalog deployments [#5120](https://github.com/pnp/powershell/pull/5120) ### Removed