Commit eda1c64e authored by Shinya Maeda's avatar Shinya Maeda Committed by Stan Hu

Generate human readable message on duplicate dotenv variables

This commit gracefully handles the variable duplicate error,
so that users can understand why the dotenv variable registration
failed.

Changelog: fixed
parent e5a2c3af
...@@ -14,7 +14,7 @@ module Ci ...@@ -14,7 +14,7 @@ module Ci
Ci::JobVariable.bulk_insert!(variables) Ci::JobVariable.bulk_insert!(variables)
success success
rescue SizeLimitError, ParserError, ActiveRecord::RecordInvalid => error rescue SizeLimitError, ParserError, ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique => error
Gitlab::ErrorTracking.track_exception(error, job_id: artifact.job_id) Gitlab::ErrorTracking.track_exception(error, job_id: artifact.job_id)
error(error.message, :bad_request) error(error.message, :bad_request)
end end
......
...@@ -23,6 +23,20 @@ RSpec.describe Ci::ParseDotenvArtifactService do ...@@ -23,6 +23,20 @@ RSpec.describe Ci::ParseDotenvArtifactService do
hash_including('key' => 'KEY2', 'value' => 'VAR2')) hash_including('key' => 'KEY2', 'value' => 'VAR2'))
end end
context 'when dotenv variables are conflicting against manual variables' do
before do
create(:ci_job_variable, job: build, key: 'KEY1')
end
it 'returns an error message that there is a duplicate variable' do
subject
expect(subject[:status]).to eq(:error)
expect(subject[:message]).to include("Key (key, job_id)=(KEY1, #{build.id}) already exists.")
expect(subject[:http_status]).to eq(:bad_request)
end
end
context 'when parse error happens' do context 'when parse error happens' do
before do before do
allow(service).to receive(:scan_line!) { raise described_class::ParserError, 'Invalid Format' } allow(service).to receive(:scan_line!) { raise described_class::ParserError, 'Invalid Format' }
......
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