Azure / enterprise-azure-policy-as-code

Enterprise-ready Azure Policy-as-Code (PaC) solution (includes Az DevOps pipeline)
https://azure.github.io/enterprise-azure-policy-as-code/
MIT License
432 stars 238 forks source link

Provide better error context for Global Settings errors #557

Closed DanZab closed 6 months ago

DanZab commented 6 months ago

Is your feature request related to a problem? Please describe. I spent 45 minutes trying to troubleshoot why my global settings were failing in v10. It took me that long to realize that there was a message being written to host explaining what element was failing

Describe the solution you'd like In the /Scripts/Helpers/Get-GlobalSettings.ps1 script, rather than writing the context-aware error message to host and passing a boolean $hasErrors value, store the message in a variable and write it to the error stream.

Example:

                $deleteOrphaned = $desired.deleteOrphanedExemptions
                if ($null -ne $deleteOrphaned) {
                    $ErrorMessage = "Error in global-settings.jsonc: pacEnvironment $pacSelector field desiredState.deleteOrphanedExemptions is deprecated. Remove it!"
                    $hasErrors = $true
                }
...

    if ($hasErrors) {
        Write-Error $ErrorMessage -ErrorAction Stop
    }
techlake commented 6 months ago

I fixed this in v10.1.1 (5 minutes from now)