lib/berkshelf/errors.rb in berkshelf-3.1.3 vs lib/berkshelf/errors.rb in berkshelf-3.1.4

- old
+ new

@@ -1,25 +1,25 @@ module Berkshelf class BerkshelfError < StandardError class << self # @param [Integer] code - def status_code(code) + def set_status_code(code) define_method(:status_code) { code } define_singleton_method(:status_code) { code } end end alias_method :message, :to_s end - class DeprecatedError < BerkshelfError; status_code(10); end - class InternalError < BerkshelfError; status_code(99); end + class DeprecatedError < BerkshelfError; set_status_code(10); end + class InternalError < BerkshelfError; set_status_code(99); end class ArgumentError < InternalError; end class AbstractFunction < InternalError; end class BerksfileNotFound < BerkshelfError - status_code(100) + set_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 @@ -29,11 +29,11 @@ "No Berksfile or Berksfile.lock found at '#{@filepath}'!" end end class CookbookNotFound < BerkshelfError - status_code(103) + set_status_code(103) def initialize(name, version, location) @name = name @version = version @location = location @@ -47,11 +47,11 @@ end end end class DuplicateDependencyDefined < BerkshelfError - status_code(105) + set_status_code(105) def initialize(name) @name = name end @@ -62,11 +62,11 @@ out end end class NoSolutionError < BerkshelfError - status_code(106) + set_status_code(106) attr_reader :demands # @param [Array<Dependency>] demands def initialize(demands, original_exception) @@ -78,16 +78,16 @@ @original_exception.to_s + "Unable to find a solution for demands: #{demands.join(', ')}" end end - class CookbookSyntaxError < BerkshelfError; status_code(107); end - class ConstraintNotSatisfied < BerkshelfError; status_code(111); end + class CookbookSyntaxError < BerkshelfError; set_status_code(107); end + class ConstraintNotSatisfied < BerkshelfError; set_status_code(111); end class BerksfileReadError < BerkshelfError - status_code(113) + set_status_code(113) - # @param [#status_code] original_error + # @param [#set_status_code] original_error def initialize(original_error) @original_error = original_error @error_message = original_error.to_s @error_backtrace = original_error.backtrace end @@ -109,11 +109,11 @@ ].join("\n") end end class MismatchedCookbookName < BerkshelfError - status_code(114) + set_status_code(114) # @param [Dependency] dependency # the dependency with the expected name # @param [CachedCookbook] cached_cookbook # the cached_cookbook with the mismatched name @@ -137,11 +137,11 @@ out end end class InvalidConfiguration < BerkshelfError - status_code(115) + set_status_code(115) def initialize(errors) @errors = errors end @@ -156,11 +156,11 @@ out.strip end end class InsufficientPrivledges < BerkshelfError - status_code(119) + set_status_code(119) def initialize(path) @path = path end @@ -170,11 +170,11 @@ "user, or choose a different path." end end class DependencyNotFound < BerkshelfError - status_code(120) + set_status_code(120) # @param [String, Array<String>] names # the list of cookbook names that were not defined def initialize(names) @names = Array(names) @@ -198,11 +198,11 @@ end end end class CommunitySiteError < BerkshelfError - status_code(123) + set_status_code(123) def initialize(uri, message) @uri = uri @message = message end @@ -212,11 +212,11 @@ "site at '#{@api_uri}'." end end class CookbookValidationFailure < BerkshelfError - status_code(124) + set_status_code(124) # @param [Location] location # the location (or any subclass) raising this validation error # @param [CachedCookbook] cached_cookbook # the cached_cookbook that does not satisfy the constraint @@ -230,11 +230,11 @@ end end class UploadFailure < BerkshelfError; end class FrozenCookbook < UploadFailure - status_code(126) + set_status_code(126) # @param [CachedCookbook] cookbook def initialize(cookbook) @cookbook = cookbook end @@ -245,11 +245,11 @@ "option to override." end end class OutdatedDependency < BerkshelfError - status_code(128) + set_status_code(128) # @param [Dependency] locked_dependency # the locked dependency # @param [Dependency] dependency # the dependency that is outdated @@ -268,11 +268,11 @@ "'#{@dependency.version_constraint}'." end end class EnvironmentNotFound < BerkshelfError - status_code(129) + set_status_code(129) def initialize(environment_name) @environment_name = environment_name end @@ -280,19 +280,19 @@ "The environment '#{@environment_name}' does not exist" end end class ChefConnectionError < BerkshelfError - status_code(130) + set_status_code(130) def to_s 'There was an error connecting to the Chef Server' end end class UnknownCompressionType < BerkshelfError - status_code(131) + set_status_code(131) def initialize(destination) @destination = destination end @@ -307,11 +307,11 @@ # @param [CachedCookbook] cookbook # the cookbook that failed validation # @param [Array<#to_s>] files # the list of files that were not valid class InvalidCookbookFiles < BerkshelfError - status_code(132) + set_status_code(132) def initialize(cookbook, files) @cookbook = cookbook @files = files end @@ -326,11 +326,11 @@ ].join("\n") end end class LicenseNotFound < BerkshelfError - status_code(134) + set_status_code(134) attr_reader :license def initialize(license) @license = license @@ -343,11 +343,11 @@ end # Raised when a cookbook or its recipes contain a space or invalid # character in the path. class ConfigNotFound < BerkshelfError - status_code(135) + set_status_code(135) # @param [String] type # the type of config that was not found (Berkshelf, Chef, etc) # @param [#to_s] path # the path to the specified Chef config that did not exist @@ -360,11 +360,11 @@ "No #{@type.capitalize} config file found at: '#{@path}'!" end end class LockfileParserError < BerkshelfError - status_code(136) + set_status_code(136) # @param [String] lockfile # the path to the Lockfile # @param [~Exception] original # the original exception class @@ -377,11 +377,11 @@ " #{@original.class}: #{@original.message}" end end class InvalidSourceURI < BerkshelfError - status_code(137) + set_status_code(137) def initialize(url, reason = nil) @url = url @reason = reason end @@ -391,22 +391,22 @@ msg << " #{@reason}." unless @reason.nil? msg end end - class DuplicateDemand < BerkshelfError; status_code(138); end - class VendorError < BerkshelfError; status_code(139); end + class DuplicateDemand < BerkshelfError; set_status_code(138); end + class VendorError < BerkshelfError; set_status_code(139); end class LockfileNotFound < BerkshelfError - status_code(140) + set_status_code(140) def to_s 'Lockfile not found! Run `berks install` to create the lockfile.' end end class NotACookbook < BerkshelfError - status_code(141) + set_status_code(141) # @param [String] path # the path to the thing that is not a cookbook def initialize(path) @path = File.expand_path(path) rescue path @@ -416,22 +416,22 @@ "The resource at '#{@path}' does not appear to be a valid cookbook. " \ "Does it have a metadata.rb?" end end - class PackageError < BerkshelfError; status_code(143); end + class PackageError < BerkshelfError; set_status_code(143); end class LockfileOutOfSync < BerkshelfError - status_code(144) + set_status_code(144) def to_s 'The lockfile is out of sync! Run `berks install` to sync the lockfile.' end end class DependencyNotInstalled < BerkshelfError - status_code(145) + set_status_code(145) def initialize(dependency) @name = dependency.name @version = dependency.locked_version end @@ -441,35 +441,35 @@ "`berks install` to download and install the missing dependency." end end class NoAPISourcesDefined < BerkshelfError - status_code(146) + set_status_code(146) def to_s "Your Berksfile does not define any API sources! You must define " \ "at least one source in order to download cookbooks. To add the " \ "default Berkshelf API server, add the following code to the top of " \ "your Berksfile:" \ "\n\n" \ - " source 'https://api.berkshelf.com'" + " source 'https://supermarket.getchef.com'" end end class GraphvizNotInstalled < BerkshelfError - status_code(147) + set_status_code(147) def to_s "Graphviz is not installed! In order to generate a dependency graph, " \ "you must install Graphviz. Please visit the Graphviz homepage at " \ "http://www.graphviz.org/ or consult your package manager for more " \ "information on how to install Graphviz." end end class GraphvizCommandFailed < BerkshelfError - status_code(148) + set_status_code(148) def initialize(command, output) @command = command @output = output end @@ -478,12 +478,23 @@ "The Graphviz command `#{@command}` failed to execute properly. Here " \ "is the standard error from the command:\n\n#{@output}" end end + class MissingLockfileCookbookVersion < CookbookNotFound + set_status_code(149) + + def to_s + super + " " \ + "This can happen if the remote cookbook has been deleted or if the sources inside the Berksfile have changed. " \ + "Please run `berks update #{@name}` to resolve to a valid version." + end + end + + # Git errors # ------------------------------ - class GitError < BerkshelfError; status_code(400); end + class GitError < BerkshelfError; set_status_code(400); end class GitNotInstalled < GitError def initialize super 'You need to install Git before you can download ' \ 'cookbooks from git repositories. For more information, please ' \