lib/berkshelf/errors.rb in berkshelf-2.0.18 vs lib/berkshelf/errors.rb in berkshelf-3.0.0.beta1

- old
+ new

@@ -9,32 +9,20 @@ end alias_method :message, :to_s end + class DeprecatedError < BerkshelfError; status_code(10); end class InternalError < BerkshelfError; status_code(99); end class ArgumentError < InternalError; end class AbstractFunction < InternalError def to_s 'Function must be implemented on includer' end end - class BerksfileNotFound < BerkshelfError - status_code(100) - - # @param [#to_s] filepath - # the path where a Berksfile was not found - def initialize(filepath) - @filepath = File.dirname(File.expand_path(filepath)) rescue filepath - end - - def to_s - "No Berksfile or Berksfile.lock found at '#{@filepath}'!" - end - end - + class BerksfileNotFound < BerkshelfError; status_code(100); end class NoVersionForConstraints < BerkshelfError; status_code(101); end class DuplicateLocationDefined < BerkshelfError; status_code(102); end class CookbookNotFound < BerkshelfError; status_code(103); end class GitError < BerkshelfError status_code(104) @@ -91,12 +79,27 @@ "", ].join("\n") end end - class DuplicateSourceDefined < BerkshelfError; status_code(105); end - class NoSolution < BerkshelfError; status_code(106); end + class DuplicateDependencyDefined < BerkshelfError; status_code(105); end + + class NoSolutionError < BerkshelfError + status_code(106) + + attr_reader :demands + + # @param [Array<Berkshelf::Dependency>] demands + def initialize(demands) + @demands = demands + end + + def to_s + "Unable to find a solution for demands: #{demands.join(', ')}" + end + end + class CookbookSyntaxError < BerkshelfError; status_code(107); end class InvalidGitURI < BerkshelfError status_code(110) @@ -130,20 +133,20 @@ '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 class BerksfileReadError < BerkshelfError + status_code(113) + # @param [#status_code] original_error def initialize(original_error) @original_error = original_error @error_message = original_error.to_s @error_backtrace = original_error.backtrace end - status_code(113) def status_code @original_error.respond_to?(:status_code) ? @original_error.status_code : 113 end @@ -162,24 +165,24 @@ end class MismatchedCookbookName < BerkshelfError status_code(114) - # @param [Berkshelf::Location] location - # the location that is mismatched + # @param [Berkshelf::Dependency] dependency + # the dependency with the expected name # @param [Berkshelf::CachedCookbook] cached_cookbook - # the cached_cookbook that is mismatched - def initialize(location, cached_cookbook) - @location = location + # the cached_cookbook with the mismatched name + def initialize(dependency, cached_cookbook) + @dependency = dependency @cached_cookbook = cached_cookbook end def to_s [ "In your Berksfile, you have:", "", - " cookbook '#{@location.name}'", + " cookbook '#{@dependency.name}'", "", "But that cookbook is actually named '#{@cached_cookbook.cookbook_name}'", "", "This can cause potentially unwanted side-effects in the future", "", @@ -204,11 +207,11 @@ end class ConfigExists < BerkshelfError; status_code(116); end class ConfigurationError < BerkshelfError; status_code(117); end class InsufficientPrivledges < BerkshelfError; status_code(119); end - class ExplicitCookbookNotFound < BerkshelfError; status_code(120); end + class DependencyNotFound < BerkshelfError; status_code(120); end class ValidationFailed < BerkshelfError; status_code(121); end class InvalidVersionConstraint < BerkshelfError; status_code(122); end class CommunitySiteError < BerkshelfError; status_code(123); end class CookbookValidationFailure < BerkshelfError @@ -216,71 +219,45 @@ # @param [Berkshelf::Location] location # the location (or any subclass) raising this validation error # @param [Berkshelf::CachedCookbook] cached_cookbook # the cached_cookbook that does not satisfy the constraint - def initialize(location, cached_cookbook) - @location = location + def initialize(dependency, cached_cookbook) + @dependency = dependency @cached_cookbook = cached_cookbook end def to_s - [ - "The cookbook downloaded from #{@location.to_s}:", - " #{@cached_cookbook.cookbook_name} (#{@cached_cookbook.version})", - "", - "does not satisfy the version constraint:", - " #{@cached_cookbook.cookbook_name} (#{@location.version_constraint})", - "", - "This occurs when the Chef Server has a cookbook with a missing/mis-matched version number in its `metadata.rb`", - ].join("\n") + "The cookbook downloaded for #{@dependency} did not satisfy the constraint." end end class ClientKeyFileNotFound < BerkshelfError; status_code(125); end class UploadFailure < BerkshelfError; end class FrozenCookbook < UploadFailure; status_code(126); end - class InvalidSiteShortnameError < BerkshelfError - status_code(127) - # @param [String,Symbol] shortname - # the shortname for the site (see SiteLocation::SHORTNAMES) - def initialize(shortname) - @shortname = shortname - end - - def to_s - [ - "Unknown site shortname '#{@shortname}' - supported shortnames are:", - "", - " * " + SiteLocation::SHORTNAMES.keys.join("\n * "), - ].join("\n") - end - end - - class OutdatedCookbookSource < BerkshelfError + class OutdatedDependency < BerkshelfError status_code(128) - # @param [Berkshelf::CookbookSource] source - # the cookbook source that is outdated - def initialize(locked_source, source) - @locked_source = locked_source - @source = source + # @param [Berkshelf::Dependency] locked_dependency + # the locked dependency + # @param [Berkshelf::Dependency] dependency + # the dependency that is outdated + def initialize(locked_dependency, dependency) + @locked_dependency = locked_dependency + @dependency = dependency end def to_s - [ - "Berkshelf could not find compatible versions for cookbook '#{@source.name}':", - " In Berksfile:", - " #{@source.name} (#{@source.version_constraint})", - "", - " In Berksfile.lock:", - " #{@locked_source.name} (#{@locked_source.locked_version})", - "", - "Try running `berks update #{@source.name}, which will try to find '#{@source.name}' matching '#{@source.version_constraint}'.", - ].join("\n") + "Berkshelf could not find compatible versions for cookbook '#{@dependency.name}':\n" + + " In Berksfile:\n" + + " #{@dependency.name} (#{@dependency.version_constraint})\n\n" + + " In Berksfile.lock:\n" + + " #{@locked_dependency.name} (#{@locked_dependency.locked_version})\n\n" + + "Try running `berks update #{@dependency.name}, which will try to find '#{@dependency.name}' matching " + + "'#{@dependency.version_constraint}'." end end class EnvironmentNotFound < BerkshelfError status_code(129) @@ -292,12 +269,10 @@ def to_s "The environment '#{@environment_name}' does not exist" end end - class EnvironmentFileNotFound < BerkshelfError; status_code(137); end - class ChefConnectionError < BerkshelfError status_code(130) def to_s 'There was an error connecting to the Chef Server' @@ -409,6 +384,24 @@ def to_s "Error reading the Berkshelf lockfile `#{@lockfile}` (#{@original.class})" end end + + class InvalidSourceURI < BerkshelfError + status_code(137) + + attr_reader :reason + + def initialize(url, reason = nil) + @url = url + @reason = reason + end + + def to_s + msg = "'#{@url}' is not a valid Berkshelf source URI." + msg + " #{reason}." unless reason.nil? + end + end + + class DuplicateDemand < BerkshelfError; status_code(138); end end