Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal ProcessOutputObject(object data, MinishellStream stream)
}
}

#nullable enable
#nullable enable
/// <summary>
/// This exception is used by the NativeCommandProcessor to indicate an error
/// when a native command returns a non-zero exit code.
Expand Down Expand Up @@ -187,7 +187,7 @@ internal NativeCommandExitException(string path, int exitCode, int processId, st
public int ProcessId { get; }

}
#nullable restore
#nullable restore

/// <summary>
/// Provides way to create and execute native commands.
Expand Down Expand Up @@ -972,11 +972,17 @@ internal override void Complete()
}

const string errorId = nameof(CommandBaseStrings.ProgramExitedWithNonZeroCode);
#if UNIX
string hexFormatStr = "0x{0:X2}";
#else
string hexFormatStr = "0x{0:X8}";
#endif

string errorMsg = StringUtil.Format(
CommandBaseStrings.ProgramExitedWithNonZeroCode,
NativeCommandName,
_nativeProcess.ExitCode);
_nativeProcess.ExitCode,
string.Format(CultureInfo.InvariantCulture, hexFormatStr, _nativeProcess.ExitCode));

var exception = new NativeCommandExitException(
Path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
however that is used for ApplicationFailedExceptions thrown when the NativeCommandProcessor fails in an unexpected way.
In this case, we have a more specific error for the native command scenario, so the two are not conflated.
-->
<value>Program "{0}" ended with non-zero exit code: {1}.</value>
<value>Program "{0}" ended with non-zero exit code: {1} ({2}).</value>
</data>
<data name="ShouldProcessMessage" xml:space="preserve">
<value>Performing the operation "{0}" on target "{1}".</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Describe 'Native command error handling tests' -Tags 'CI' {

$error[0].FullyQualifiedErrorId | Should -BeExactly 'ProgramExitedWithNonZeroCode'
$error[0].TargetObject | Should -BeExactly $exePath
$stderr[1].Exception.Message | Should -BeExactly "Program `"$exeName`" ended with non-zero exit code: 1."
$stderr[1].Exception.Message | Should -BeExactly ("Program `"$exeName`" ended with non-zero exit code: 1 ({0})." -f ($IsWindows ? '0x00000001' : '0x01'))
}

It "Non-boolean value should not cause type casting error when the native command exited with non-zero code" {
Expand All @@ -61,7 +61,7 @@ Describe 'Native command error handling tests' -Tags 'CI' {

$error[0].FullyQualifiedErrorId | Should -BeExactly 'ProgramExitedWithNonZeroCode'
$error[0].TargetObject | Should -BeExactly $exePath
$stderr[1].Exception.Message | Should -BeExactly "Program `"$exeName`" ended with non-zero exit code: 1."
$stderr[1].Exception.Message | Should -BeExactly ("Program `"$exeName`" ended with non-zero exit code: 1 ({0})." -f ($IsWindows ? '0x00000001' : '0x01'))
}

It 'Non-zero exit code generates a non-teminating error for $ErrorActionPreference = ''SilentlyContinue''' {
Expand Down
Loading