From 5193747ca72f3100b754e906ac00366f32233c6a Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Fri, 25 Apr 2014 15:01:34 -0500 Subject: [PATCH 1/2] Gracefully handle unexpected source structure Closes https://github.com/CocoaPods/Core/issues/110 --- CHANGELOG.md | 4 ++++ lib/cocoapods-core/source/file_system_data_provider.rb | 7 ++++++- spec/source/file_system_data_provider_spec.rb | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e2487dc9..d7da31f93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ [#115](https://github.com/CocoaPods/Core/issues/115) [#116](https://github.com/CocoaPods/Core/pull/116) +* Gracefully handle unexpected source structure + [Samuel E. Giddins](https://github.com/segiddins) + [#110](https://github.com/CocoaPods/Core/issues/110) + ## 0.32.1 ## 0.32.0 diff --git a/lib/cocoapods-core/source/file_system_data_provider.rb b/lib/cocoapods-core/source/file_system_data_provider.rb index 4b0e0faf6..c6d553466 100644 --- a/lib/cocoapods-core/source/file_system_data_provider.rb +++ b/lib/cocoapods-core/source/file_system_data_provider.rb @@ -58,7 +58,12 @@ def versions(name) return unless pod_dir.exist? pod_dir.children.map do |v| basename = v.basename.to_s - Version.new(basename) if v.directory? && basename[0, 1] != '.' + begin + Version.new(basename) if v.directory? && basename[0, 1] != '.' + rescue ArgumentError => e + raise Informative, "An unexpected directory (#{basename}) " \ + "was encountered in the #{name} repository" + end end.compact.sort.reverse.map(&:to_s) end diff --git a/spec/source/file_system_data_provider_spec.rb b/spec/source/file_system_data_provider_spec.rb index 594e5df88..692c27aad 100644 --- a/spec/source/file_system_data_provider_spec.rb +++ b/spec/source/file_system_data_provider_spec.rb @@ -66,6 +66,14 @@ module Pod @subject.versions(nil) end.message.should.match /No name/ end + + it 'raises if a non-version-name directory is encountered' do + Pathname.any_instance.stubs(:children).returns([Pathname.new('/Hello')]) + Pathname.any_instance.stubs(:directory?).returns(true) + e = lambda { @subject.versions('JSONKit') }.should.raise Informative + e.message.should.match /Hello/ + e.message.should.not.match /Malformed version number string/ + end end #-------------------------------------------------------------------------# From 7269c76ea34e6634da7ded4b0df62302cec7dc4b Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Tue, 29 Apr 2014 18:28:01 -0500 Subject: [PATCH 2/2] Make unexpected source structure `Informative` even more informative --- lib/cocoapods-core/source/file_system_data_provider.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-core/source/file_system_data_provider.rb b/lib/cocoapods-core/source/file_system_data_provider.rb index c6d553466..7fe39ded4 100644 --- a/lib/cocoapods-core/source/file_system_data_provider.rb +++ b/lib/cocoapods-core/source/file_system_data_provider.rb @@ -61,8 +61,9 @@ def versions(name) begin Version.new(basename) if v.directory? && basename[0, 1] != '.' rescue ArgumentError => e - raise Informative, "An unexpected directory (#{basename}) " \ - "was encountered in the #{name} repository" + raise Informative, 'An unexpected version directory ' \ + "`#{basename}` was encountered for the " \ + "`#{pod_dir}` Pod in the `#{name}` repository." end end.compact.sort.reverse.map(&:to_s) end