Skip to content

Commit c01156e

Browse files
tristanlabellecompnerd
authored andcommitted
Add more details when a command invocation fails.
1 parent dc52dcb commit c01156e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

build.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,23 @@ function Invoke-Program()
255255

256256
if ($LastExitCode -ne 0)
257257
{
258-
$callstack = @(Get-PSCallStack) -Join "`n"
259-
throw "Command execution returned $LastExitCode. Call stack:`n$callstack"
258+
$ErrorMessage = "Error: $([IO.Path]::GetFileName($Executable)) exited with code $($LastExitCode).`n"
259+
260+
$ErrorMessage += "Invocation:`n"
261+
$ErrorMessage += " $Executable $Args`n"
262+
263+
$ErrorMessage += "Call stack:`n"
264+
foreach ($Frame in @(Get-PSCallStack)) {
265+
$ErrorMessage += " $Frame`n"
266+
}
267+
268+
$ErrorMessage += "Environment:`n"
269+
foreach ($EnvVar in ((Get-ChildItem env:*).GetEnumerator() | Sort-Object Key))
270+
{
271+
$ErrorMessage += " $($EnvVar.Key)=$($EnvVar.Value)`n"
272+
}
273+
274+
throw $ErrorMessage
260275
}
261276
}
262277
}

0 commit comments

Comments
 (0)