Commit 9a2ee677 authored by Avielle Wolfe's avatar Avielle Wolfe Committed by Furkan Ayhan

Fix TypeError from Tags::Reference

Some missing references were raising a TypeError when using `dig` to
extract the referenced object from a reference, in cases where the
reference included too many symbols and we ended up attempting to
extract a value from an array using a symbol.

This commit fixes the issue by rescuing from TypeError and properly
returning a message stating that the given reference cannot be found in
the given configuration.

Changelog: fixed
parent 51038dff
......@@ -27,7 +27,7 @@ module Gitlab
override :_resolve
def _resolve(resolver)
object = resolver.config.dig(*location)
object = config_at_location(resolver)
value = resolver.deep_resolve(object)
raise MissingReferenceError, missing_ref_error_message unless value
......@@ -35,6 +35,12 @@ module Gitlab
value
end
def config_at_location(resolver)
resolver.config.dig(*location)
rescue TypeError
raise MissingReferenceError, missing_ref_error_message
end
def missing_ref_error_message
"#{data[:tag]} #{data[:seq].inspect} could not be found"
end
......
......@@ -69,6 +69,23 @@ RSpec.describe Gitlab::Ci::Config::Yaml::Tags::Reference do
end
end
context 'when the references are valid but do not match the config' do
let(:yaml) do
<<~YML
a: [1, 2]
b: [3, 4]
c: !reference [a, b]
YML
end
it 'raises a MissingReferenceError' do
expect { subject }.to raise_error(
Gitlab::Ci::Config::Yaml::Tags::Reference::MissingReferenceError,
'!reference ["a", "b"] could not be found'
)
end
end
context 'with arrays' do
let(:yaml) do
<<~YML
......
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