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 module Pod
class Informative < StandardError
end
autoload :Command, 'cocoa_pods/command' autoload :Command, 'cocoa_pods/command'
autoload :Config, 'cocoa_pods/config' autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency' autoload :Dependency, 'cocoa_pods/dependency'
......
...@@ -5,7 +5,7 @@ module Pod ...@@ -5,7 +5,7 @@ module Pod
autoload :Setup, 'cocoa_pods/command/setup' autoload :Setup, 'cocoa_pods/command/setup'
autoload :Spec, 'cocoa_pods/command/spec' autoload :Spec, 'cocoa_pods/command/spec'
class Help < Exception class Help < Informative
def initialize(command_class, argv) def initialize(command_class, argv)
@command_class, @argv = command_class, argv @command_class, @argv = command_class, argv
end end
...@@ -46,7 +46,7 @@ module Pod ...@@ -46,7 +46,7 @@ module Pod
def self.run(*argv) def self.run(*argv)
parse(*argv).run parse(*argv).run
rescue Exception => e 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 " \ puts "Oh no, an error occurred. Please run with `--verbose' and report " \
"on https://github.com/alloy/cocoa-pods/issues." "on https://github.com/alloy/cocoa-pods/issues."
puts "" puts ""
......
...@@ -32,13 +32,13 @@ module Pod ...@@ -32,13 +32,13 @@ module Pod
if @podspec.exist? if @podspec.exist?
spec = Specification.from_podspec(@podspec) spec = Specification.from_podspec(@podspec)
else else
raise "The specified podspec `#{@podspec}' doesn't exist." raise Help, "The specified podspec `#{@podspec}' doesn't exist."
end end
else else
if config.project_podfile.exist? if config.project_podfile.exist?
spec = Specification.from_podfile(config.project_podfile) spec = Specification.from_podfile(config.project_podfile)
else else
raise "No Podfile found in current working directory." raise Help, "No Podfile found in current working directory."
end end
end end
Installer.new(spec, config.project_pods_root).install! Installer.new(spec, config.project_pods_root).install!
......
...@@ -30,7 +30,7 @@ module Pod ...@@ -30,7 +30,7 @@ module Pod
case @action = argv.arguments[0] case @action = argv.arguments[0]
when 'add' when 'add'
unless (@name = argv[1]) && (@url = argv[2]) 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 end
when 'update' when 'update'
@name = argv[1] @name = argv[1]
......
module Pod module Pod
class Source class Source
def self.all 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 end
def self.search(dependency) def self.search(dependency)
all.map { |source| source.search(dependency) }.compact.first || 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 end
attr_reader :repo attr_reader :repo
......
...@@ -28,7 +28,7 @@ module Pod ...@@ -28,7 +28,7 @@ module Pod
dependency = specification.dependency_by_name(name) dependency = specification.dependency_by_name(name)
unless @required_by.empty? || dependency.requirement.satisfied_by?(required_version) unless @required_by.empty? || dependency.requirement.satisfied_by?(required_version)
# TODO add graph that shows which dependencies led to this. # TODO add graph that shows which dependencies led to this.
raise "#{specification} tries to activate `#{dependency}', " \ raise Informative, "#{specification} tries to activate `#{dependency}', " \
"but already activated version `#{required_version}' " \ "but already activated version `#{required_version}' " \
"by #{@required_by.join(', ')}." "by #{@required_by.join(', ')}."
end end
...@@ -59,10 +59,8 @@ module Pod ...@@ -59,10 +59,8 @@ module Pod
# Return the first version that matches the current dependency. # Return the first version that matches the current dependency.
def required_version def required_version
unless v = versions.find { |v| dependency.match?(name, v) } versions.find { |v| dependency.match?(name, v) } ||
raise "Required version (#{dependency}) not found for `#{name}'." raise(Informative, "Required version (#{dependency}) not found for `#{name}'.")
end
v
end end
def ==(other) def ==(other)
......
...@@ -23,6 +23,6 @@ describe "Pod::Source" do ...@@ -23,6 +23,6 @@ describe "Pod::Source" do
it "raises if a specification set can't be found" do it "raises if a specification set can't be found" do
lambda { lambda {
Pod::Source.search(Pod::Dependency.new('DoesNotExist')) Pod::Source.search(Pod::Dependency.new('DoesNotExist'))
}.should.raise }.should.raise Pod::Informative
end end
end end
...@@ -38,12 +38,14 @@ describe "Pod::Specification::Set" do ...@@ -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.7.9' })
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '~> 1.8.0' }) @set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '~> 1.8.0' })
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest' }) @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 end
it "raises if the required version doesn't exist" do it "raises if the required version doesn't exist" do
@set.required_by(Pod::Spec.new { dependency 'ASIHTTPRequest', '< 1.8' }) @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 end
before do 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