Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…to user error and make Command::Help a subclass of Informative.
  • Loading branch information...
commit d3f9746991b9bc5bba1b750602086fc2546e8be8 1 parent 19faee3
@alloy alloy authored
View
3  lib/cocoa_pods.rb
@@ -1,4 +1,7 @@
module Pod
+ class Informative < StandardError
+ end
+
autoload :Command, 'cocoa_pods/command'
autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency'
View
4 lib/cocoa_pods/command.rb
@@ -5,7 +5,7 @@ class Command
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 @@ def self.options
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 ""
View
4 lib/cocoa_pods/command/install.rb
@@ -32,13 +32,13 @@ def run
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!
View
2  lib/cocoa_pods/command/repo.rb
@@ -30,7 +30,7 @@ def initialize(argv)
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]
View
12 lib/cocoa_pods/source.rb
@@ -1,12 +1,20 @@
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
View
12 lib/cocoa_pods/specification/set.rb
@@ -28,9 +28,9 @@ def required_by(specification)
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 @@ def specification
# 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)
View
2  spec/unit/source_spec.rb
@@ -23,6 +23,6 @@
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
View
6 spec/unit/specification/set_spec.rb
@@ -38,12 +38,14 @@ def reset!
@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
Please sign in to comment.
Something went wrong with that request. Please try again.