lib/berkshelf/errors.rb in berkshelf-1.0.4 vs lib/berkshelf/errors.rb in berkshelf-1.1.0.rc1
- old
+ new
@@ -1,5 +1,7 @@
+require 'vagrant/errors'
+
module Berkshelf
class BerkshelfError < StandardError
class << self
# @param [Integer] code
def status_code(code)
@@ -9,10 +11,38 @@
end
alias_method :message, :to_s
end
+ # A wrapper for a BerkshelfError for Vagrant. All Berkshelf exceptions should be
+ # wrapped in this proxy object so they are properly handled when Vagrant encounters
+ # an exception.
+ #
+ # @example wrapping an error encountered within the Vagrant plugin
+ # rescue BerkshelfError => e
+ # VagrantWrapperError.new(e)
+ # end
+ class VagrantWrapperError < Vagrant::Errors::VagrantError
+ # @param [BerkshelfError]
+ attr_reader :original
+
+ # @param [BerkshelfError] original
+ def initialize(original)
+ @original = original
+ end
+
+ def to_s
+ "#{original.class}: #{original.to_s}"
+ end
+
+ private
+
+ def method_missing(fun, *args, &block)
+ original.send(fun, *args, &block)
+ end
+ end
+
class InternalError < BerkshelfError; status_code(99); end
class ArgumentError < InternalError; end
class AbstractFunction < InternalError
def to_s
"Function must be implemented on includer"
@@ -34,9 +64,10 @@
def to_s
out = "An error occured during Git execution:\n"
out << stderr.prepend_each("\n", "\t")
end
end
+ class PrivateGitRepo < GitError; 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