Commit 9df0ef28 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'sh-log-error-code-export' into 'master'

Add error code to project export command status log

See merge request gitlab-org/gitlab!79193
parents b59c6630 78895a35
......@@ -81,12 +81,16 @@ module Gitlab
return true if status == 0
output = output&.strip
message = "command exited with error code #{status}"
message += ": #{output}" if output.present?
if @shared.respond_to?(:error)
@shared.error(Gitlab::ImportExport::Error.new(output.to_s))
@shared.error(Gitlab::ImportExport::Error.new(message))
false
else
raise Gitlab::ImportExport::Error, 'System call failed'
raise Gitlab::ImportExport::Error, message
end
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
......
......@@ -97,7 +97,7 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
include Gitlab::ImportExport::CommandLineUtil
end.new
expect { klass.tar_cf(archive: 'test', dir: 'test') }.to raise_error(Gitlab::ImportExport::Error, 'System call failed')
expect { klass.tar_cf(archive: 'test', dir: 'test') }.to raise_error(Gitlab::ImportExport::Error, 'command exited with error code 1: Error')
end
end
end
......@@ -125,14 +125,31 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
end
context 'when something goes wrong' do
it 'raises an error' do
before do
expect(Gitlab::Popen).to receive(:popen).and_return(['Error', 1])
end
it 'raises an error' do
klass = Class.new do
include Gitlab::ImportExport::CommandLineUtil
end.new
expect { klass.untar_xf(archive: 'test', dir: 'test') }.to raise_error(Gitlab::ImportExport::Error, 'System call failed')
expect { klass.untar_xf(archive: 'test', dir: 'test') }.to raise_error(Gitlab::ImportExport::Error, 'command exited with error code 1: Error')
end
it 'returns false and includes error status' do
klass = Class.new do
include Gitlab::ImportExport::CommandLineUtil
attr_accessor :shared
def initialize
@shared = Gitlab::ImportExport::Shared.new(nil)
end
end.new
expect(klass.tar_czf(archive: 'test', dir: 'test')).to eq(false)
expect(klass.shared.errors).to eq(['command exited with error code 1: Error'])
end
end
end
......
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