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` ...@@ -12,6 +12,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes ##### 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. * Only share pod target xcscheme if present during validation.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso) [Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6558](https://github.com/CocoaPods/CocoaPods/pull/6558) [#6558](https://github.com/CocoaPods/CocoaPods/pull/6558)
......
...@@ -111,11 +111,15 @@ module Pod ...@@ -111,11 +111,15 @@ module Pod
title = "Pre-downloading: `#{name}` #{description}" title = "Pre-downloading: `#{name}` #{description}"
UI.titled_section(title, :verbose_prefix => '-> ') do UI.titled_section(title, :verbose_prefix => '-> ') do
target = sandbox.pod_dir(name) target = sandbox.pod_dir(name)
begin
download_result = Downloader.download(download_request, target, :can_cache => can_cache) 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 spec = download_result.spec
raise Informative, "Unable to find a specification for '#{name}'." unless spec
store_podspec(sandbox, spec) store_podspec(sandbox, spec)
sandbox.store_pre_downloaded_pod(name) sandbox.store_pre_downloaded_pod(name)
sandbox.store_checkout_source(name, download_result.checkout_options) sandbox.store_checkout_source(name, download_result.checkout_options)
...@@ -147,6 +151,7 @@ module Pod ...@@ -147,6 +151,7 @@ module Pod
# @return [void] # @return [void]
# #
def store_podspec(sandbox, spec, json = false) def store_podspec(sandbox, spec, json = false)
begin
spec = case spec spec = case spec
when Pathname when Pathname
Specification.from_file(spec) Specification.from_file(spec)
...@@ -159,6 +164,9 @@ module Pod ...@@ -159,6 +164,9 @@ module Pod
else else
raise "Unknown spec type: #{spec}" raise "Unknown spec type: #{spec}"
end end
rescue Pod::DSLError => e
raise Informative, "Failed to load '#{name}' podspec: #{e.message}"
end
spec.defined_in_file = nil spec.defined_in_file = nil
validate_podspec(spec) validate_podspec(spec)
sandbox.store_podspec(name, spec.to_pretty_json, true, true) sandbox.store_podspec(name, spec.to_pretty_json, true, true)
......
...@@ -12,13 +12,9 @@ module Pod ...@@ -12,13 +12,9 @@ module Pod
@specs_by_name = {} @specs_by_name = {}
spec_files = Pathname.glob(root + '{,*}.podspec{,.json}') spec_files = Pathname.glob(root + '{,*}.podspec{,.json}')
spec_files.sort_by { |p| -p.to_path.split(File::SEPARATOR).size }.each do |file| spec_files.sort_by { |p| -p.to_path.split(File::SEPARATOR).size }.each do |file|
begin
spec = Specification.from_file(file) spec = Specification.from_file(file)
spec.validate_cocoapods_version spec.validate_cocoapods_version
@specs_by_name[spec.name] = spec @specs_by_name[spec.name] = spec
rescue => e
UI.warn "Unable to load a podspec from `#{file.basename}`, skipping:\n\n#{e}"
end
end end
@specs_by_name @specs_by_name
end end
......
...@@ -26,6 +26,36 @@ module Pod ...@@ -26,6 +26,36 @@ module Pod
@subject.fetch(config.sandbox) @subject.fetch(config.sandbox)
config.sandbox.specification('Reachability').name.should == 'Reachability' config.sandbox.specification('Reachability').name.should == 'Reachability'
end 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 end
#--------------------------------------# #--------------------------------------#
......
...@@ -15,12 +15,6 @@ module Pod ...@@ -15,12 +15,6 @@ module Pod
@finder.podspecs.should.be.empty @finder.podspecs.should.be.empty
end 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 it 'ignores podspecs not in the root' do
path = @root + 'Dir/RestKit.podspec.json' path = @root + 'Dir/RestKit.podspec.json'
path.parent.mkpath 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