Skip to content

Commit 81b46f2

Browse files
committed
fix: Handle SplitOverProps JSON errors and cleanup
Wrap processing of entity.SplitOverProps in a try/catch/finally block to stop and handle ConvertFrom-Json errors (-ErrorAction Stop). On failure, emit a warning including the entity's PartitionKey and RowKey so problematic rows can be identified. Always remove the SplitOverProps property in the finally block to ensure cleanup and prevent leftover properties even when parsing fails.
1 parent cd45e78 commit 81b46f2

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

Modules/CIPPCore/Public/Get-CIPPAzDatatableEntity.ps1

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,21 @@ function Get-CIPPAzDataTableEntity {
8181

8282
foreach ($entity in $finalResults) {
8383
if ($entity.SplitOverProps) {
84-
$splitInfoList = $entity.SplitOverProps | ConvertFrom-Json
85-
foreach ($splitInfo in $splitInfoList) {
86-
$mergedData = [string]::Join('', ($splitInfo.SplitHeaders | ForEach-Object { $entity.$_ }))
87-
$entity | Add-Member -NotePropertyName $splitInfo.OriginalHeader -NotePropertyValue $mergedData -Force
88-
$propsToRemove = $splitInfo.SplitHeaders
89-
foreach ($prop in $propsToRemove) {
90-
$entity.PSObject.Properties.Remove($prop)
84+
try {
85+
$splitInfoList = $entity.SplitOverProps | ConvertFrom-Json -ErrorAction Stop
86+
foreach ($splitInfo in $splitInfoList) {
87+
$mergedData = [string]::Join('', ($splitInfo.SplitHeaders | ForEach-Object { $entity.$_ }))
88+
$entity | Add-Member -NotePropertyName $splitInfo.OriginalHeader -NotePropertyValue $mergedData -Force
89+
$propsToRemove = $splitInfo.SplitHeaders
90+
foreach ($prop in $propsToRemove) {
91+
$entity.PSObject.Properties.Remove($prop)
92+
}
9193
}
94+
} catch {
95+
Write-Warning "Failed to process SplitOverProps for entity with PartitionKey='$($entity.PartitionKey)' and RowKey='$($entity.RowKey)': $($_.Exception.Message)"
96+
} finally {
97+
$entity.PSObject.Properties.Remove('SplitOverProps')
9298
}
93-
$entity.PSObject.Properties.Remove('SplitOverProps')
9499
}
95100
}
96101

0 commit comments

Comments
 (0)