Skip to content

Commit 9ece8de

Browse files
committed
harden orc start and audit log error message
1 parent 42e980b commit 9ece8de

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Modules/CIPPCore/Public/AuditLogs/New-CippAuditLogSearch.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ function New-CippAuditLogSearch {
189189
message = [string]'Unified auditing is disabled for this tenant.'
190190
}
191191
}
192+
193+
# Handle Microsoft-side timeouts / transient errors (e.g. UnknownError with empty message)
194+
$ErrorCode = $AuditLogError.error.code ?? $AuditLogError.code
195+
if ($ErrorCode -in @('UnknownError', 'ServiceUnavailable', 'RequestTimeout', 'GatewayTimeout', 'TooManyRequests')) {
196+
Write-LogMessage -API 'Audit Logs' -tenant $TenantFilter -message "Audit log search creation failed with transient error for tenant $TenantFilter ($ErrorCode) - will retry next cycle" -sev Warning
197+
return [PSCustomObject]@{
198+
id = $null
199+
displayName = [string]$DisplayName
200+
status = [string]$ErrorCode
201+
cippStatus = [string]'TransientError'
202+
message = [string]"Microsoft returned $ErrorCode - search will be retried next cycle."
203+
}
204+
}
205+
192206
throw
193207
}
194208

Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-CIPPOrchestrator.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ function Start-CIPPOrchestrator {
3737
# ─── CIPPNG runtime: push batch directly to OrchestratorService ───
3838
if ($env:CIPPNG -eq 'true' -and $InputObject) {
3939
$OrchestratorName = $InputObject.OrchestratorName ?? 'UnnamedOrchestrator'
40+
41+
# QueueFunction pattern: call the function first to generate batch items
42+
if (-not $InputObject.Batch -and $InputObject.QueueFunction) {
43+
$QueueFuncName = "Push-$($InputObject.QueueFunction.FunctionName)"
44+
Write-Information "CIPP-NG: Calling QueueFunction '$QueueFuncName' to build batch for '$OrchestratorName'"
45+
$QueueItem = [PSCustomObject]@{}
46+
if ($InputObject.QueueFunction.Parameters) {
47+
$QueueItem = [PSCustomObject]$InputObject.QueueFunction.Parameters
48+
}
49+
$BatchResult = & $QueueFuncName -Item $QueueItem
50+
$InputObject.Batch = @($BatchResult | Where-Object { $null -ne $_ })
51+
if ($InputObject.Batch.Count -eq 0) {
52+
Write-Information "CIPP-NG: QueueFunction '$QueueFuncName' returned 0 tasks for '$OrchestratorName' - skipping"
53+
return "CIPPNG-$OrchestratorName-NoTasks"
54+
}
55+
}
56+
4057
$BatchJson = ConvertTo-Json -InputObject @($InputObject.Batch) -Depth 10 -Compress
4158

4259
$PostExecFunctionName = $null

0 commit comments

Comments
 (0)