Exception: TTY::Command::ExitError Private

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/tty/command/exit_error.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An ExitError reports an unsuccessful exit by command.

The error message includes:

* the name of command executed
* the exit status
* stdout bytes
* stderr bytes

Instance Method Summary collapse

Constructor Details

#initialize(cmd_name, result) ⇒ ExitError

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ExitError.



15
16
17
# File 'lib/tty/command/exit_error.rb', line 15

def initialize(cmd_name, result)
  super(info(cmd_name, result))
end

Instance Method Details

#extract_output(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/tty/command/exit_error.rb', line 26

def extract_output(value)
  (value || "").strip.empty? ? "Nothing written" : value.strip
end

#info(cmd_name, result) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
# File 'lib/tty/command/exit_error.rb', line 19

def info(cmd_name, result)
  "Running `#{cmd_name}` failed with\n" \
  "  exit status: #{result.exit_status}\n" \
  "  stdout: #{extract_output(result.out)}\n" \
  "  stderr: #{extract_output(result.err)}\n"
end