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 and its result are available from this object.

This 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_data = {
  command: ['exit 1'],
  options: ProcessExecuter::Options::RunOptions.new,
  timed_out: false,
  elapsed_time: 0.01
}
result = ProcessExecuter::Result.new($?, **result_data)
error = ProcessExecuter::CommandError.new(result)
error.to_s #=> '["exit 1"], status: pid 29686 exit 1'

Parameters:



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

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

Instance Attribute Details

#resultProcessExecuter::Result (readonly)

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

Examples:

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

Returns:



127
128
129
# File 'lib/process_executer/errors.rb', line 127

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'

Returns:

  • (String)


114
115
116
# File 'lib/process_executer/errors.rb', line 114

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