Sha256: 655975f5f70243dd224153f5d3d286454eee40208858914759c96d50be5dd3b1

Contents?: true

Size: 837 Bytes

Versions: 5

Compression:

Stored size: 837 Bytes

Contents

# encoding: utf-8
# 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

5 entries across 5 versions & 1 rubygems

Version Path
tty-command-0.8.2 lib/tty/command/exit_error.rb
tty-command-0.8.1 lib/tty/command/exit_error.rb
tty-command-0.8.0 lib/tty/command/exit_error.rb
tty-command-0.7.0 lib/tty/command/exit_error.rb
tty-command-0.6.0 lib/tty/command/exit_error.rb