lib/berkshelf/errors.rb in berkshelf-3.0.0.beta6 vs lib/berkshelf/errors.rb in berkshelf-3.0.0.beta7

- old
+ new

@@ -270,13 +270,21 @@ def initialize(cookbooks) @cookbooks = Array(cookbooks) end def to_s - list = @cookbooks.collect {|c| "'#{c}'" } - "Could not find cookbook(s) #{list.join(', ')} in any of the configured" << - " dependencies. #{list.size == 1 ? 'Is it' : 'Are they' } in your Berksfile?" + list = @cookbooks.collect { |cookbook| "'#{cookbook}'" }.join(', ') + + if @cookbooks.size == 1 + "Could not find cookbook #{list}. Make sure it is in your " \ + "Berksfile, then run `berks install` to download and install the " \ + "missing dependencies." + else + "Could not find cookbooks #{list}. Make sure they are in your " \ + "Berksfile, then run `berks install` to download and install the " \ + "missing dependencies." + end end end class ValidationFailed < BerkshelfError; status_code(121); end class InvalidVersionConstraint < BerkshelfError; status_code(122); end @@ -323,21 +331,21 @@ # @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 + def initialize(locked, dependency) + @locked = locked + @dependency = dependency end def to_s "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" + + " #{@locked.name} (#{@locked.version})\n\n" + "Try running `berks update #{@dependency.name}`, which will try to find '#{@dependency.name}' matching " + "'#{@dependency.version_constraint}'." end end @@ -457,17 +465,17 @@ # @param [String] lockfile # the path to the Lockfile # @param [~Exception] original # the original exception class - def initialize(lockfile, original) - @lockfile = Pathname.new(lockfile.to_s).basename.to_s + def initialize(original) @original = original end def to_s - "Error reading the Berkshelf lockfile `#{@lockfile}` (#{@original.class})" + "Error reading the Berkshelf lockfile:\n\n" \ + " #{@original.class}: #{@original.message}" end end class InvalidSourceURI < BerkshelfError status_code(137) @@ -485,12 +493,18 @@ end end class DuplicateDemand < BerkshelfError; status_code(138); end class VendorError < BerkshelfError; status_code(139); end - class LockfileNotFound < BerkshelfError; status_code(140); end + class LockfileNotFound < BerkshelfError + status_code(140) + def to_s + 'Lockfile not found! Run `berks install` to create the lockfile.' + end + end + class NotACookbook < BerkshelfError status_code(141) # @param [String] path # the path to the thing that is not a cookbook @@ -503,6 +517,40 @@ end end class InvalidLockFile < BerkshelfError; status_code(142); end class PackageError < BerkshelfError; status_code(143); end + + class LockfileOutOfSync < BerkshelfError + 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) + + def initialize(dependency) + name = dependency.name + version = dependency.locked_version + + super "The cookbook '#{name} (#{version})' is not installed. Please " \ + "run `berks install` to download and install the missing " \ + "dependency." + end + end + + class NoAPISourcesDefined < BerkshelfError + status_code(146) + + def initialize + super "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'" + end + end end