win_command, win_shell: Use Fail-Json on failure (#26512)
Two reasons to do this: - It provides a proper error message indicating why it failed - It conforms to what is being done in the command and shell modules
This commit is contained in:
parent
5617d68c3e
commit
18d9c34e9d
3 changed files with 9 additions and 9 deletions
|
@ -159,14 +159,14 @@ $proc.WaitForExit() | Out-Null
|
|||
|
||||
$result.rc = $proc.ExitCode
|
||||
|
||||
If ($result.rc -ne 0) {
|
||||
$result.failed = $true
|
||||
}
|
||||
|
||||
$end_datetime = [DateTime]::UtcNow
|
||||
|
||||
$result.start = $start_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff")
|
||||
$result.end = $end_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff")
|
||||
$result.delta = $($end_datetime - $start_datetime).ToString("h\:mm\:ss\.ffffff")
|
||||
|
||||
If ($result.rc -ne 0) {
|
||||
Fail-Json -obj $result -message "non-zero return code"
|
||||
}
|
||||
|
||||
Exit-Json $result
|
||||
|
|
|
@ -56,7 +56,7 @@ $result.runtime_seconds = $stopwatch.Elapsed.TotalSeconds
|
|||
$result.sent_localtime = $endsend_at.Trim()
|
||||
|
||||
if ($result.rc -ne 0 ) {
|
||||
Fail-Json $result "$output"
|
||||
Fail-Json -obj $result -message "$output"
|
||||
}
|
||||
|
||||
Exit-Json $result
|
||||
|
|
|
@ -168,14 +168,14 @@ $proc.WaitForExit() | Out-Null
|
|||
|
||||
$result.rc = $proc.ExitCode
|
||||
|
||||
If ($result.rc -ne 0) {
|
||||
$result.failed = $true
|
||||
}
|
||||
|
||||
$end_datetime = [DateTime]::UtcNow
|
||||
|
||||
$result.start = $start_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff")
|
||||
$result.end = $end_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff")
|
||||
$result.delta = $($end_datetime - $start_datetime).ToString("h\:mm\:ss\.ffffff")
|
||||
|
||||
If ($result.rc -ne 0) {
|
||||
Fail-Json -obj $result -message "non-zero return code"
|
||||
}
|
||||
|
||||
Exit-Json $result
|
||||
|
|
Loading…
Reference in a new issue