Commit d3f97469 authored by Eloy Duran's avatar Eloy Duran

Raise an Informative exception if a problem is (most likely) related to user…

Raise an Informative exception if a problem is (most likely) related to user error and make Command::Help a subclass of Informative.
parent 19faee3a
module Pod
class Informative < StandardError
end
autoload :Command, 'cocoa_pods/command'
autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency'
......
......@@ -5,7 +5,7 @@ module Pod
autoload :Setup, 'cocoa_pods/command/setup'
autoload :Spec, 'cocoa_pods/command/spec'
class Help < Exception
class Help < Informative
def initialize(command_class, argv)
@command_class, @argv = command_class, argv
end
......@@ -46,7 +46,7 @@ module Pod
def self.run(*argv)
parse(*argv).run
rescue Exception => e
unless e.is_a?(Help)
unless e.is_a?(Informative)
puts "Oh no, an error occurred. Please run with `--verbose' and report " \
"on https://github.com/alloy/cocoa-pods/issues."
puts ""
......
......@@ -32,13 +32,13 @@ module Pod
if @podspec.exist?
spec = Specification.from_podspec(@podspec)
else
raise "The specified podspec `#{@podspec}' doesn't exist."
raise Help, "The specified podspec `#{@podspec}' doesn't exist."
end
else
if config.project_podfile.exist?
spec = Specification.from_podfile(config.project_podfile)
else
raise "No Podfile found in current working directory."
raise Help, "No Podfile found in current working directory."
end
end
Installer.new(spec, config.project_pods_root).install!
......
......@@ -30,7 +30,7 @@ module Pod
case @action = argv.arguments[0]
when 'add'
unless (@name = argv[1]) && (@url = argv[2])
raise ArgumentError, "needs a NAME and URL"
raise Help, "Adding a repo needs a `name' and a `url'."
end
when 'update'
@name = argv[1]
......
module Pod
class Source
def self.all
@sources ||= Config.instance.repos_dir.children.select(&:directory?).map { |repo| new(repo) }
@sources ||= begin
repos_dir = Config.instance.repos_dir
sources = repos_dir.children.select(&:directory?).map { |repo| new(repo) }
if sources.empty?
raise Informative, "No spec repos found in `#{repos_dir}'. " \
"To fetch the `master' repo run: $ pod setup"
end
sources
end
end
def self.search(dependency)
all.map { |source| source.search(dependency) }.compact.first ||
raise("Unable to find a pod named `#{dependency.name}'")
raise(Informative, "Unable to find a pod named `#{dependency.name}'")
end
attr_reader :repo
......
......@@ -28,9 +28,9 @@ module Pod
dependency = specification.dependency_by_name(name)
unless @required_by.empty? || dependency.requirement.satisfied_by?(required_version)
# TODO add graph that shows which dependencies led to this.
raise "#{specification} tries to activate `#{dependency}', " \
"but already activated version `#{required_version}' " \
"by #{@required_by.join(', ')}."
raise Informative, "#{specification} tries to activate `#{dependency}', " \
"but already activated version `#{required_version}' " \
"by #{@required_by.join(', ')}."
end
@required_by << specification
end
......@@ -59,10 +59,8 @@ module Pod
# Return the first version that matches the current dependency.
def required_version
unless v = versions.find { |v| dependency.match?(name, v) }
raise "Required version (#{dependency}) not found for `#{name}'."
end
v
versions.find { |v| dependency.match?(name, v) } ||
raise(Informative, "Required version (#{dependency}) not found for `#{name}'.")
end
def ==(other)
......
......@@ -23,6 +23,6 @@ describe "Pod::Source" do
it "raises if a specification set can't be found" do
lambda {
Pod::Source.search(Pod::Dependency.new('DoesNotExist'))
}.should.raise
}.should.raise Pod::Informative
end
end
......@@ -38,12 +38,14 @@ describe "Pod::Specification::Set" do
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '> 1.7.9' })
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '~> 1.8.0' })
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest' })
lambda { @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8' }) }.should.raise
lambda {
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8' })
}.should.raise Pod::Informative
end
it "raises if the required version doesn't exist" do
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8' })
lambda { @set.required_version }.should.raise
lambda { @set.required_version }.should.raise Pod::Informative
end
before do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment