Private/Invoke-KadenOperatorModelApplySafe.ps1
|
function Invoke-KadenOperatorModelApplySafe { <# .SYNOPSIS Run the apply step without failing the caller when the operator file is bad. #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$ChildRoot ) $operatorRelative = '.kaden.model.json' $operatorPath = Join-Path $ChildRoot $operatorRelative try { $before = Get-KadenOperatorFileFingerprint -LiteralPath $operatorPath return Invoke-KadenOperatorModelApplyCore -ChildRoot $ChildRoot } catch { $after = Get-KadenOperatorFileFingerprint -LiteralPath $operatorPath $unchanged = $false if ($null -ne $before) { $unchanged = Test-KadenOperatorFileBytesUnchanged -Before $before -After $after } $outcome = New-KadenOperatorModelApplyOutcome -Status 'failed' -Reason "operator model apply failed: $($_.Exception.Message)" -Path $ChildRoot -OperatorFile $operatorRelative -OperatorFileBytesUnchanged $unchanged -Changed $false -Stacks @() -TunedFiles @() -NotTuned @() try { Write-KadenOperatorModelOutcome -ChildRoot $ChildRoot -Outcome $outcome } catch { $outcome.Reason = "$($outcome.Reason); outcome file was not recorded: $($_.Exception.Message)" } return $outcome } } |