Specify exe path as TargetObect for non-zero exit code ErrorRecord (#16108)

This commit is contained in:
Keith Hill
2021-10-14 14:47:54 -07:00
committed by GitHub
parent 9a63f412ef
commit b94dd91e74
2 changed files with 6 additions and 5 deletions
@@ -884,7 +884,7 @@ namespace System.Management.Automation
errorMsg,
errorId);
var errorRecord = new ErrorRecord(exception, errorId, ErrorCategory.NotSpecified, targetObject: NativeCommandName);
var errorRecord = new ErrorRecord(exception, errorId, ErrorCategory.NotSpecified, targetObject: Path);
this.commandRuntime._WriteErrorSkipAllowCheck(errorRecord);
}
}
@@ -14,6 +14,7 @@ Describe 'Native command error handling tests' -Tags 'CI' {
}
$exeName = $IsWindows ? 'testexe.exe' : 'testexe'
$exePath = @(Get-Command $exeName -Type Application)[0].Path
$errorActionPrefTestCases = @(
@{ ErrorActionPref = 'Stop' }
@@ -43,7 +44,7 @@ Describe 'Native command error handling tests' -Tags 'CI' {
$error.Count | Should -Be 1
$error[0].FullyQualifiedErrorId | Should -BeExactly 'ProgramExitedWithNonZeroCode'
$error[0].TargetObject | Should -BeExactly $exeName
$error[0].TargetObject | Should -BeExactly $exePath
}
It 'Non-zero exit code outputs a non-teminating error for $ErrorActionPreference = ''Continue''' {
@@ -52,7 +53,7 @@ Describe 'Native command error handling tests' -Tags 'CI' {
$stderr = testexe -returncode 1 2>&1
$error[0].FullyQualifiedErrorId | Should -BeExactly 'ProgramExitedWithNonZeroCode'
$error[0].TargetObject | Should -BeExactly $exeName
$error[0].TargetObject | Should -BeExactly $exePath
$stderr[1].Exception.Message | Should -BeExactly "Program `"$exeName`" ended with non-zero exit code: 1."
}
@@ -65,7 +66,7 @@ Describe 'Native command error handling tests' -Tags 'CI' {
$stderr = testexe -returncode 1 2>&1
$error[0].FullyQualifiedErrorId | Should -BeExactly 'ProgramExitedWithNonZeroCode'
$error[0].TargetObject | Should -BeExactly $exeName
$error[0].TargetObject | Should -BeExactly $exePath
$stderr[1].Exception.Message | Should -BeExactly "Program `"$exeName`" ended with non-zero exit code: 1."
}
@@ -76,7 +77,7 @@ Describe 'Native command error handling tests' -Tags 'CI' {
$error.Count | Should -Be 1
$error[0].FullyQualifiedErrorId | Should -BeExactly 'ProgramExitedWithNonZeroCode'
$error[0].TargetObject | Should -BeExactly $exeName
$error[0].TargetObject | Should -BeExactly $exePath
}
It 'Non-zero exit code does not generates an error record for $ErrorActionPreference = ''Ignore''' {