From 4d85593df8cdb89bc33710e0eb4b207bc379d94e Mon Sep 17 00:00:00 2001 From: Thomas Hu Date: Fri, 4 Sep 2020 15:20:40 -0400 Subject: [PATCH] Add better handling of errors on request (#99) * Add better handling of errors on request * Add more invalid directories --- CHANGELOG.md | 4 ++++ codecov.gemspec | 2 +- lib/codecov.rb | 15 ++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3970c61..40b521c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### `0.2.10` +- Adds better logging on error cases +- Add more invalid directories in the network + ### `0.2.9` - Remove `String` specific colors - Add support for Codebuild CI diff --git a/codecov.gemspec b/codecov.gemspec index 81d39dc..dfd74b9 100644 --- a/codecov.gemspec +++ b/codecov.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>=2.4' s.summary = 'hosted code coverage ruby/rails reporter' s.test_files = ['test/test_codecov.rb'] - s.version = '0.2.9' + s.version = '0.2.10' s.add_dependency 'json' s.add_dependency 'simplecov' diff --git a/lib/codecov.rb b/lib/codecov.rb index a38bafa..9833916 100644 --- a/lib/codecov.rb +++ b/lib/codecov.rb @@ -7,7 +7,7 @@ require 'zlib' class SimpleCov::Formatter::Codecov - VERSION = '0.2.9' + VERSION = '0.2.10' ### CIs RECOGNIZED_CIS = [ @@ -319,6 +319,7 @@ def retry_request(req, https) puts 'Error uploading coverage reports to Codecov. Sorry' puts e.class.name puts e + puts "Backtrace:\n\t#{e.backtrace}" return response end @@ -414,7 +415,7 @@ def upload_to_v4(url, report, query, query_without_token) ) req.body = report res = retry_request(req, https) - if res.body == '' + if res&.body == '' { 'uploaded' => true, 'url' => reports_url, @@ -425,7 +426,7 @@ def upload_to_v4(url, report, query, query_without_token) }.to_json else puts [black('-> '), 'Could not upload reports via v4 API, defaulting to v2'].join(' ') - puts red(res.body) + puts red(res&.body || 'nil') nil end end @@ -508,16 +509,20 @@ def file_network ].freeze invalid_directories = [ - 'node_modules/' + 'node_modules/', + 'public/', + 'storage/', + 'tmp/' ] puts [green('==>'), 'Appending file network'].join(' ') network = [] Dir['**/*'].keep_if do |file| - if File.file?(file) && !file.end_with?(*invalid_file_types) && !file.include?(*invalid_directories) + if File.file?(file) && !file.end_with?(*invalid_file_types) && invalid_directories.none? { |dir| file.include?(dir) } network.push(file) end end + network.push('<<<<<< network') network end