Skip to content

Commit ec7a7c6

Browse files
authored
Merge pull request #71115 from tristanlabelle/build.ps1-detailed-exception-printing
Build.ps1: More detailed exception printing
2 parents 302e106 + efab1ff commit ec7a7c6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

utils/build.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,7 @@ function Stage-BuildArtifacts($Arch) {
17361736
}
17371737

17381738
#-------------------------------------------------------------------
1739+
try {
17391740

17401741
if (-not $SkipBuild) {
17411742
Fetch-Dependencies
@@ -1829,3 +1830,31 @@ if ($Test -contains "dispatch") { Build-Dispatch $HostArch -Test }
18291830
if ($Test -contains "foundation") { Build-Foundation $HostArch -Test }
18301831
if ($Test -contains "xctest") { Build-XCTest $HostArch -Test }
18311832
if ($Test -contains "llbuild") { Build-LLBuild $HostArch -Test }
1833+
1834+
# Custom exception printing for more detailed exception information
1835+
} catch {
1836+
function Write-ErrorLines($Text, $Indent = 0) {
1837+
$IndentString = " " * $Indent
1838+
$Text.Replace("`r", "") -split "`n" | ForEach-Object {
1839+
Write-Host "$IndentString$_" -ForegroundColor Red
1840+
}
1841+
}
1842+
1843+
Write-ErrorLines "Error: $_"
1844+
Write-ErrorLines $_.ScriptStackTrace -Indent 4
1845+
1846+
# Walk the .NET inner exception chain to print all messages and stack traces
1847+
$Exception = $_.Exception
1848+
$Indent = 2
1849+
while ($Exception -is [Exception]) {
1850+
Write-ErrorLines "From $($Exception.GetType().FullName): $($Exception.Message)" -Indent $Indent
1851+
if ($null -ne $Exception.StackTrace) {
1852+
# .NET exceptions stack traces are already indented by 3 spaces
1853+
Write-ErrorLines $Exception.StackTrace -Indent ($Indent + 1)
1854+
}
1855+
$Exception = $Exception.InnerException
1856+
$Indent += 2
1857+
}
1858+
1859+
exit 1
1860+
}

0 commit comments

Comments
 (0)