Commit 7bbd5f6e authored by Shinya Maeda's avatar Shinya Maeda

Define Trace::ArchiveError to make it explit as an error

parent 481d0bc3
module Gitlab module Gitlab
module Ci module Ci
class Trace class Trace
ArchiveError = Class.new(StandardError)
attr_reader :job attr_reader :job
delegate :old_trace, to: :job delegate :old_trace, to: :job
...@@ -94,8 +96,8 @@ module Gitlab ...@@ -94,8 +96,8 @@ module Gitlab
end end
def archive! def archive!
raise 'Already archived' if trace_artifact raise ArchiveError, 'Already archived' if trace_artifact
raise 'Job is not finished yet' unless job.complete? raise ArchiveError, 'Job is not finished yet' unless job.complete?
if current_path if current_path
File.open(current_path) do |stream| File.open(current_path) do |stream|
...@@ -124,7 +126,7 @@ module Gitlab ...@@ -124,7 +126,7 @@ module Gitlab
temp_path = File.join(dir_path, "job.log") temp_path = File.join(dir_path, "job.log")
FileUtils.touch(temp_path) FileUtils.touch(temp_path)
size = IO.copy_stream(src_stream, temp_path) size = IO.copy_stream(src_stream, temp_path)
raise 'Not all saved' unless size == src_stream.size raise ArchiveError, 'Failed to copy stream' unless size == src_stream.size
yield(temp_path) yield(temp_path)
end end
......
...@@ -463,11 +463,10 @@ describe Gitlab::Ci::Trace do ...@@ -463,11 +463,10 @@ describe Gitlab::Ci::Trace do
context 'when failed to create clone file' do context 'when failed to create clone file' do
before do before do
allow_any_instance_of(described_class) allow(IO).to receive(:copy_stream).and_return(0)
.to receive(:clone_file!).and_raise('Not all saved')
end end
it_behaves_like 'source trace file stays intact', error: 'Not all saved' it_behaves_like 'source trace file stays intact', error: Gitlab::Ci::Trace::ArchiveError
end end
context 'when failed to create job artifact record' do context 'when failed to create job artifact record' do
...@@ -494,11 +493,10 @@ describe Gitlab::Ci::Trace do ...@@ -494,11 +493,10 @@ describe Gitlab::Ci::Trace do
context 'when failed to create clone file' do context 'when failed to create clone file' do
before do before do
allow_any_instance_of(described_class) allow(IO).to receive(:copy_stream).and_return(0)
.to receive(:clone_file!).and_raise('Not all saved')
end end
it_behaves_like 'source trace in database stays intact', error: 'Not all saved' it_behaves_like 'source trace in database stays intact', error: Gitlab::Ci::Trace::ArchiveError
end end
context 'when failed to create job artifact record' do context 'when failed to create job artifact record' do
......
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