Sha256: ec35439e1e6dadab7d475c535e751996b634d9a9b3f197574a0c8003b5bf551f

Contents?: true

Size: 889 Bytes

Versions: 63

Compression:

Stored size: 889 Bytes

Contents

module Vagrant
  module Util
    # This module provides a `safe_puts` method which outputs to
    # the given IO object, and rescues any broken pipe errors and
    # ignores them. This is useful in cases where you're outputting
    # to stdout, for example, and the stdout is closed, but you want to
    # keep running.
    module SafePuts
      # Uses `puts` on the given IO object and safely ignores any
      # Errno::EPIPE.
      #
      # @param [String] message Message to output.
      # @param [Hash] opts Options hash.
      def safe_puts(message=nil, opts=nil)
        message ||= ""
        opts = {
          io: $stdout,
          printer: :puts
        }.merge(opts || {})

        begin
          opts[:io].send(opts[:printer], message)
        rescue Errno::EPIPE
          # This is what makes this a `safe` puts.
          return
        end
      end
    end
  end
end

Version data entries

63 entries across 56 versions & 8 rubygems

Version Path
vagrant-unbundled-2.3.6.0 lib/vagrant/util/safe_puts.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.3.3.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.3.2.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.19.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.18.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.16.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.14.0 lib/vagrant/util/safe_puts.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.10.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.9.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.8.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.7.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.6.2 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.6.1 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.6.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.5.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.4.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.3.0 lib/vagrant/util/safe_puts.rb
vagrant-unbundled-2.2.2.0 lib/vagrant/util/safe_puts.rb