Sha256: d37654bf008da89509770c4380dd7301a8ee47e83d20b47dbb553aeeae7d3ef8

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

require 'vagrant/errors'

module VagrantPlugins
  module Berkshelf
    INSTALL_CHEFDK_INSTRUCTIONS = <<-EOH.freeze
Please download and install the latest version of the ChefDK from:

    https://downloads.getchef.com/chef-dk

and follow the installation instructions. Do not forget to add the ChefDK to
your PATH.
EOH

    class BerkshelfNotFound < Vagrant::Errors::VagrantError
      def error_message
        <<-EOH
Vagrant Berkshelf could not find the 'berks' executable in your PATH.

#{INSTALL_CHEFDK_INSTRUCTIONS}
EOH
      end
    end

    class BerksCommandFailed < Vagrant::Errors::VagrantError
      def initialize(command, stdout, stderr)
        @command, @stdout, @stderr = command, stdout, stderr
        super
      end

      def chefdk?
        @command.include?("chefdk")
      end

      def not_chefdk_message
        <<-EOH
It appears that you are not using the ChefDK. Please note that Vagrant Berkshelf
works best when used with the ChefDK, and other installation methods are not
officially supported.

#{INSTALL_CHEFDK_INSTRUCTIONS}
EOH
      end

      def error_message
        base = <<-EOH
The following berks command failed to execute:

    #{@command}

The stdout and stderr are shown below:

    stdout: #{@stdout}
    stderr: #{@stderr}
EOH

        base << "\n#{not_chefdk_message}" if !chefdk?
        base
      end
    end

    class InvalidBerkshelfVersionError < Vagrant::Errors::VagrantError
      def initialize(bin, constraint, version)
        @bin        = bin
        @constraint = constraint
        @version    = version
        super
      end

      def error_message
        <<-EOH
The Berkshelf version at #{@bin.inspect} is invalid.
Vagrant Berkshelf requires #{@constraint}, but the current version is #{@version}.

#{INSTALL_CHEFDK_INSTRUCTIONS}
EOH
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-berkshelf-4.0.2 lib/vagrant-berkshelf/errors.rb
vagrant-berkshelf-4.0.1 lib/vagrant-berkshelf/errors.rb
vagrant-berkshelf-4.0.0 lib/vagrant-berkshelf/errors.rb