Skip to content

Commit

Permalink
Mark job as failed if errors/exceptions exist
Browse files Browse the repository at this point in the history
  • Loading branch information
devblackops authored and Tadas committed Mar 30, 2020
1 parent 338391d commit 4451920
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion PoshBot/Classes/Bot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class Bot : BaseLogger {
$this.LogInfo([LogSeverity]::Error, "Errors encountered running command [$($cmdExecContext.FullyQualifiedCommandName)]", $cmdExecContext.Result.Errors)
}
} else {
$this.LogVerbose('Command execution result', $cmdExecContext.Result)
$this.LogVerbose('Command execution result', $cmdExecContext.Result.Output)
foreach ($resultOutput in $cmdExecContext.Result.Output) {
if ($null -ne $resultOutput) {
if ($this._IsCustomResponse($resultOutput)) {
Expand Down
3 changes: 0 additions & 3 deletions PoshBot/Classes/CommandExecutor.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,9 @@ class CommandExecutor : BaseLogger {
$this.LogVerbose("Job [$($cmdExecContext.Id)] is complete")
$cmdExecContext.Complete = $true
$cmdExecContext.Ended = (Get-Date).ToUniversalTime()

$cmdExecContext.RunspaceJob.EndJob([ref]$cmdExecContext.Result)


$this.LogVerbose("Command [$($cmdExecContext.FullyQualifiedCommandName)] completed with successful result [$($cmdExecContext.Result.Success)]")

}

# Determine if job had any terminating errors and capture error stream
Expand Down
8 changes: 5 additions & 3 deletions PoshBot/Classes/RunspaceJob.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ class RunspaceJob {
$CommandResult.Value.Streams.Verbose = $this.PowerShell.Streams.Verbose.ReadAll()
$CommandResult.Value.Streams.Warning = $this.PowerShell.Streams.Warning.ReadAll()

$CommandResult.Value.Success = $true
try {
$CommandResult.Value.Output = $this.PowerShell.EndInvoke($this.Handle)
} catch {
$CommandResult.Value.Success = $false
# Unwrap the exception otherwise it will blame EndInvoke for the exception
# e.g. Exception calling "EndInvoke" with "1" argument(s): "Attempted to divide by zero."
$CommandResult.Value.Errors = $_.Exception.InnerException.ErrorRecord
} finally {
$this.PowerShell.Dispose()
}
$this.PowerShell.Dispose()

# # Job is deemed successful if no items in error stream
$CommandResult.Value.Success = $CommandResult.Value.Errors -eq 0
}
}

0 comments on commit 4451920

Please sign in to comment.