Exception: ProcessExecuter::CommandError

Inherits:
Error
  • Object
show all
Defined in:
lib/process_executer/errors.rb

Overview

Raised when a command fails or exits because of an uncaught signal

The command executed, status, stdout, and stderr are available from this object.

The Gem will raise a more specific error for each type of failure:

Direct Known Subclasses

FailedError, SignaledError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ CommandError

Create a CommandError object

Examples:

`exit 1` # set $? appropriately for this example
result = ProcessExecuter::Result.new(%w[git status], $?, 'stdout', 'stderr')
error = ProcessExecuter::CommandError.new(result)
error.to_s #=> '["git", "status"], status: pid 89784 exit 1, stderr: "stderr"'

Parameters:

  • result (Result)

    The result of the command including the command, status, stdout, and stderr

[View source]

78
79
80
81
# File 'lib/process_executer/errors.rb', line 78

def initialize(result)
  @result = result
  super(error_message)
end

Instance Attribute Details

#resultResult (readonly)

The result of the command including the command, its status and its output

Examples:

error.result #=> #<ProcessExecuter::Result:0x00007f9b1b8b3d20>

Returns:


103
104
105
# File 'lib/process_executer/errors.rb', line 103

def result
  @result
end

Instance Method Details

#error_messageString

The human readable representation of this error

Examples:

error.error_message #=> '["git", "status"], status: pid 89784 exit 1, stderr: "stderr"'

Returns:

  • (String)
[View source]

90
91
92
# File 'lib/process_executer/errors.rb', line 90

def error_message
  "#{result.command}, status: #{result}, stderr: #{result.stderr.inspect}"
end