Skip to content

Commit

Permalink
Do not crash if appdata is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
dmacvicar committed Feb 20, 2018
1 parent 0aff171 commit 63d9d57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/appdata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ def self.get_distribution(dist = 'factory', flavour = 'oss')
else
"http://download.opensuse.org/distribution/#{dist}/repo/#{flavour}/suse/setup/descr/appdata.xml.gz"
end
Nokogiri::XML(Zlib::GzipReader.new(open(appdata_url)))
begin
Nokogiri::XML(Zlib::GzipReader.new(open(appdata_url)))
rescue StandardError => e
Rails.logger.error e
Rails.logger.error "Can't retrieve appdata from: '#{appdata_url}'"
Nokogiri::XML('<?xml version="1.0" encoding="UTF-8"?><components origin="appdata" version="0.8"></components>')
end
end

end
8 changes: 8 additions & 0 deletions test/models/appdata_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ class AppdataTest < ActiveSupport::TestCase
assert_equal 4, pkg_list.size
assert_equal ['0ad', '4pane', 'opera', 'steam'], pkg_list
end

test 'Missing appdata should not raise anything' do
stub_content("download.opensuse.org/tumbleweed/repo/oss/suse/setup/descr/appdata.xml.gz", status: [404, "Not found"])
appdata = Appdata.get('factory')
# Should at least include the standard searches
assert_not_empty appdata[:apps]
assert_includes appdata[:apps].map { |e| e[:name] }, 'Opera'
end
end

0 comments on commit 63d9d57

Please sign in to comment.