Provide a better error message if a podspec is found but cannot be parsed

parent f5d7b5bc
......@@ -12,6 +12,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes
* Provide a better error message if a podspec is found but cannot be parsed.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6457](https://github.com/CocoaPods/CocoaPods/issues/6457)
* Only share pod target xcscheme if present during validation.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6558](https://github.com/CocoaPods/CocoaPods/pull/6558)
......
......@@ -111,11 +111,15 @@ module Pod
title = "Pre-downloading: `#{name}` #{description}"
UI.titled_section(title, :verbose_prefix => '-> ') do
target = sandbox.pod_dir(name)
download_result = Downloader.download(download_request, target, :can_cache => can_cache)
begin
download_result = Downloader.download(download_request, target, :can_cache => can_cache)
rescue Pod::DSLError => e
raise Informative, "Failed to load '#{name}' podspec: #{e.message}"
rescue => _
raise Informative, "Unable to find a specification for '#{name}'."
end
spec = download_result.spec
raise Informative, "Unable to find a specification for '#{name}'." unless spec
store_podspec(sandbox, spec)
sandbox.store_pre_downloaded_pod(name)
sandbox.store_checkout_source(name, download_result.checkout_options)
......@@ -147,17 +151,21 @@ module Pod
# @return [void]
#
def store_podspec(sandbox, spec, json = false)
spec = case spec
when Pathname
Specification.from_file(spec)
when String
path = "#{name}.podspec"
path << '.json' if json
Specification.from_string(spec, path)
when Specification
spec.dup
else
raise "Unknown spec type: #{spec}"
begin
spec = case spec
when Pathname
Specification.from_file(spec)
when String
path = "#{name}.podspec"
path << '.json' if json
Specification.from_string(spec, path)
when Specification
spec.dup
else
raise "Unknown spec type: #{spec}"
end
rescue Pod::DSLError => e
raise Informative, "Failed to load '#{name}' podspec: #{e.message}"
end
spec.defined_in_file = nil
validate_podspec(spec)
......
......@@ -12,13 +12,9 @@ module Pod
@specs_by_name = {}
spec_files = Pathname.glob(root + '{,*}.podspec{,.json}')
spec_files.sort_by { |p| -p.to_path.split(File::SEPARATOR).size }.each do |file|
begin
spec = Specification.from_file(file)
spec.validate_cocoapods_version
@specs_by_name[spec.name] = spec
rescue => e
UI.warn "Unable to load a podspec from `#{file.basename}`, skipping:\n\n#{e}"
end
spec = Specification.from_file(file)
spec.validate_cocoapods_version
@specs_by_name[spec.name] = spec
end
@specs_by_name
end
......
......@@ -26,6 +26,36 @@ module Pod
@subject.fetch(config.sandbox)
config.sandbox.specification('Reachability').name.should == 'Reachability'
end
it 'raises appropriate error if a DSLError was raised' do
Downloader.stubs(:download).raises(Pod::DSLError.new('Invalid `Reachability.podspec` file:', 'some/path/to/podspec', Exception.new('Error Message')))
should.raise(Informative) do
e = @subject.send(:pre_download, config.sandbox)
e.message.should.include "Failed to load 'Reachability' podspec:"
e.message.should.include 'Invalid `Reachability.podspec` file:'
end
end
it 'raises appropriate error if a DSLError when storing a podspec from string' do
podspec = 'Pod::Spec.new do |s|; error; end'
should.raise(Informative) { @subject.send(:store_podspec, config.sandbox, podspec) }.
message.should.include "Invalid `Reachability.podspec` file: undefined local variable or method `error'"
end
it 'raises appropriate error if a DSLError when storing a podspec from file' do
podspec = 'Pod::Spec.new do |s|; error; end'
path = SpecHelper.temporary_directory + 'BananaLib.podspec'
File.open(path, 'w') { |f| f.write(podspec) }
should.raise(Informative) { @subject.send(:store_podspec, config.sandbox, path) }.
message.should.include "Invalid `BananaLib.podspec` file: undefined local variable or method `error'"
end
it 'raises a generic error if a podspec was not found' do
Downloader.stubs(:download).raises(Pod::Downloader::DownloaderError.new('Some generic exception'))
should.raise(Informative) do
@subject.send(:pre_download, config.sandbox).message.should == "Unable to find a specification for 'Reachability'."
end
end
end
#--------------------------------------#
......
......@@ -15,12 +15,6 @@ module Pod
@finder.podspecs.should.be.empty
end
it "warns when a found podspec can't be parsed" do
@root.+('RestKit.podspec.json').open('w') { |f| f << '{]' }
@finder.podspecs.should.be.empty
UI.warnings.should.include "Unable to load a podspec from `RestKit.podspec.json`, skipping:\n\n"
end
it 'ignores podspecs not in the root' do
path = @root + 'Dir/RestKit.podspec.json'
path.parent.mkpath
......
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