diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index 2c5efb3566..ca38b337b8 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -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); } } diff --git a/test/powershell/engine/Basic/NativeCommandErrorHandling.Tests.ps1 b/test/powershell/engine/Basic/NativeCommandErrorHandling.Tests.ps1 index b8d6b20e12..055382bb5e 100644 --- a/test/powershell/engine/Basic/NativeCommandErrorHandling.Tests.ps1 +++ b/test/powershell/engine/Basic/NativeCommandErrorHandling.Tests.ps1 @@ -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''' {