Skip to content

Commit

Permalink
Specify exe path as TargetObect for non-zero exit code ErrorRecord (P…
Browse files Browse the repository at this point in the history
  • Loading branch information
rkeithhill authored and TrapGodBrim committed Jan 19, 2022
1 parent f704e04 commit 7e6c472
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ internal override void Complete()
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -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''' {
Expand All @@ -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."
}

Expand All @@ -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."
}

Expand All @@ -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''' {
Expand Down

0 comments on commit 7e6c472

Please sign in to comment.