Skip to content

Commit

Permalink
Failure to parse a single artifact should not cause all artifacts to …
Browse files Browse the repository at this point in the history
…fail (#66)
  • Loading branch information
alekstorm authored Mar 31, 2021
1 parent 25e9687 commit 4628f22
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
19 changes: 13 additions & 6 deletions lib/test_summary_buildkite_plugin/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ def files
Agent.run('artifact', 'download', artifact_path, WORKDIR)
Dir.glob("#{WORKDIR}/#{artifact_path}")
rescue Agent::CommandFailed => err
if fail_on_error
raise
else
Utils.log_error(err)
[]
end
handle_error(err)
[]
end
end

Expand All @@ -63,6 +59,9 @@ def fail_on_error

def filename_to_failures(filename)
file_contents_to_failures(read(filename)).each { |failure| failure.job_id = job_id(filename) }
rescue StandardError => err
handle_error(err)
[]
end

def job_id(filename)
Expand All @@ -78,6 +77,14 @@ def job_id_regex
DEFAULT_JOB_ID_REGEX
end
end

def handle_error(err)
if fail_on_error
raise err
else
Utils.log_error(err)
end
end
end

class OneLine < Base
Expand Down
26 changes: 24 additions & 2 deletions spec/test_summary_buildkite_plugin/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
describe 'setting ascii encoding' do
let(:type) { 'oneline' }
let(:artifact_path) { 'eslint-00112233-0011-0011-0011-001122334455.txt' }
let(:additional_options) { { encoding: 'ascii' } }
let(:additional_options) { { encoding: 'ascii', fail_on_error: true } }

it 'tries to parse as ascii' do
expect { input.failures }.to raise_error('invalid byte sequence in US-ASCII')
Expand Down Expand Up @@ -301,7 +301,7 @@
end

context 'with bad custom job_id_regex' do
let(:additional_options) { { job_id_regex: '(eslint)' } }
let(:additional_options) { { job_id_regex: '(eslint)', fail_on_error: true } }
let(:artifact_path) { 'eslint-00112233-0011-0011-0011-001122334455.txt' }

it 'gives helpful error' do
Expand Down Expand Up @@ -338,4 +338,26 @@
end
end
end

describe 'parsing exceptions' do
let(:type) { 'oneline' }
let(:artifact_path) { 'rubocop.txt' }

before do
allow(input).to receive(:file_contents_to_failures).and_raise('no good')
end

it 'handles the error' do
expect { input.failures }.to output(/no good/).to_stdout
expect(input.failures).to be_empty
end

describe 'with fail_on_error' do
let(:additional_options) { { fail_on_error: true } }

it 're-raises the error' do
expect { input.failures }.to raise_error('no good')
end
end
end
end

0 comments on commit 4628f22

Please sign in to comment.