Sha256: fbdfe88194096b17d576ee0a4777bece343c185475089e9aa917af70ec1884de

Contents?: true

Size: 819 Bytes

Versions: 2

Compression:

Stored size: 819 Bytes

Contents

# frozen_string_literal: true

module TTY
  class Command
    # An ExitError reports an unsuccessful exit by command.
    #
    # The error message includes:
    #  * the name of command executed
    #  * the exit status
    #  * stdout bytes
    #  * stderr bytes
    #
    # @api private
    class ExitError < RuntimeError
      def initialize(cmd_name, result)
        super(info(cmd_name, result))
      end

      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

      def extract_output(value)
        (value || "").strip.empty? ? "Nothing written" : value.strip
      end
    end # ExitError
  end # Command
end # TTY

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tty-command-0.10.1 lib/tty/command/exit_error.rb
tty-command-0.10.0 lib/tty/command/exit_error.rb