mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Improve error message from Start-NativeExecution (#26500)
This commit is contained in:
@@ -16,6 +16,8 @@ function script:Start-NativeExecution {
|
||||
$ErrorActionPreference = "Continue"
|
||||
Write-Verbose "Executing: $ScriptBlock"
|
||||
try {
|
||||
$cwd = Get-Location
|
||||
|
||||
if ($VerboseOutputOnError.IsPresent) {
|
||||
$output = & $ScriptBlock 2>&1
|
||||
} else {
|
||||
@@ -36,10 +38,10 @@ function script:Start-NativeExecution {
|
||||
$callerFile = $callerLocationParts[0]
|
||||
$callerLine = $callerLocationParts[1]
|
||||
|
||||
$errorMessage = "Execution of {$ScriptBlock} by ${callerFile}: line $callerLine failed with exit code $LASTEXITCODE"
|
||||
$errorMessage = "Execution of {$ScriptBlock} in '$cwd' by ${callerFile}: line $callerLine failed with exit code $LASTEXITCODE"
|
||||
throw $errorMessage
|
||||
}
|
||||
throw "Execution of {$ScriptBlock} failed with exit code $LASTEXITCODE"
|
||||
throw "Execution of {$ScriptBlock} in '$cwd' failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
} finally {
|
||||
$ErrorActionPreference = $backupEAP
|
||||
|
||||
Reference in New Issue
Block a user