lib/berkshelf/errors.rb in berkshelf-1.4.6 vs lib/berkshelf/errors.rb in berkshelf-2.0.0.beta
- old
+ new
@@ -115,12 +115,44 @@
def status_code
@original_error.respond_to?(:status_code) ? @original_error.status_code : 113
end
end
- class AmbiguousCookbookName < BerkshelfError; status_code(114); end
+ # @author Seth Vargo <sethvargo@gmail.com>
+ class MismatchedCookbookName < BerkshelfError
+ status_code(114)
+ # @return [Berkshelf::Location]
+ attr_reader :location
+
+ # @return [Berkshelf::CachedCookbook]
+ attr_reader :cached_cookbook
+
+ # @param [Berkshelf::Location] location
+ # the location that is mismatched
+ # @param [Berkshelf::CachedCookbook] cached_cookbook
+ # the cached_cookbook that is mismatched
+ def initialize(location, cached_cookbook)
+ @location = location
+ @cached_cookbook = cached_cookbook
+ end
+
+ def to_s
+ [
+ "In your Berksfile, you have:",
+ "",
+ " cookbook '#{location.name}'",
+ "",
+ "But that cookbook is actually named '#{cached_cookbook.cookbook_name}'.",
+ "",
+ "This can cause potentially unwanted side-effects in the future.",
+ "",
+ "NOTE: If you don't explicitly set the `name` attribute in the metadata, the name of the directory will be used!"
+ ].join("\n")
+ end
+ end
+
class InvalidConfiguration < BerkshelfError
status_code(115)
def initialize(errors)
@errors = errors
@@ -145,18 +177,45 @@
class InsufficientPrivledges < BerkshelfError; status_code(119); end
class ExplicitCookbookNotFound < 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; status_code(124); end
+
+ class CookbookValidationFailure < BerkshelfError
+ status_code(124)
+
+ # @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
+ @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")
+ 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
@@ -220,35 +279,8 @@
end
def to_s
"The file at '#{@destination}' is not a known compression type!"
end
- end
- # @author Seth Vargo <sethvargo@gmail.com>
- #
- # Raised when a cookbook or its recipes contain a space or invalid
- # character in the path.
- #
- # @param [Berkshelf::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)
-
- def initialize(cookbook, files)
- @cookbook = cookbook
- @files = files
- end
-
- def to_s
- [
- "The cookbook '#{@cookbook.cookbook_name}' has invalid filenames:",
- "",
- " " + @files.map(&:to_s).join("\n "),
- "",
- "Please note, spaces are not a valid character in filenames."
- ].join("\n")
- end
end
end