Sha256: 72072b05db65bff3584ca5f9caca23c0a7b1650c40b796c1ed68c0d8cf88f0b3

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

module Berkshelf
  class BerkshelfError < StandardError
    class << self
      # @param [Integer] code
      def status_code(code)
        define_method(:status_code) { code }
        define_singleton_method(:status_code) { code }
      end
    end

    alias_method :message, :to_s
  end

  class InternalError < BerkshelfError; status_code(99); end
  class BerksfileNotFound < BerkshelfError; status_code(100); end
  class NoVersionForConstraints < BerkshelfError; status_code(101); end
  class DownloadFailure < BerkshelfError; status_code(102); end
  class CookbookNotFound < BerkshelfError; status_code(103); end
  class GitError < BerkshelfError
    status_code(104)
    attr_reader :stderr

    def initialize(stderr)
      @stderr = stderr
    end

    def to_s
      out = "An error occured during Git execution:\n"
      out << stderr.prepend_each("\n", "\t")
    end
  end

  class DuplicateSourceDefined < BerkshelfError; status_code(105); end
  class NoSolution < BerkshelfError; status_code(106); end
  class CookbookSyntaxError < BerkshelfError; status_code(107); end
  class UploadFailure < BerkshelfError; status_code(108); end
  class KnifeConfigNotFound < BerkshelfError; status_code(109); end

  class InvalidGitURI < BerkshelfError
    status_code(110)
    attr_reader :uri

    # @param [String] uri
    def initialize(uri)
      @uri = uri
    end

    def to_s
      "'#{uri}' is not a valid Git URI."
    end
  end

  class GitNotFound < BerkshelfError
    status_code(110)

    def to_s
      "Could not find a Git executable in your path. Please add it and try again."
    end
  end

  class ConstraintNotSatisfied < BerkshelfError; status_code(111); end
  class InvalidChefAPILocation < BerkshelfError; status_code(112); end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
berkshelf-0.4.0.rc2 lib/berkshelf/errors.rb
berkshelf-0.4.0.rc1 lib/berkshelf/errors.rb