Commit b83fa58f authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve extended CI/CD config error messages

parent d7133d94
...@@ -3,12 +3,12 @@ module Gitlab ...@@ -3,12 +3,12 @@ module Gitlab
class Config class Config
class Extendable class Extendable
class Entry class Entry
MAX_NESTING_LEVELS = 10
InvalidExtensionError = Class.new(Extendable::ExtensionError) InvalidExtensionError = Class.new(Extendable::ExtensionError)
CircularDependencyError = Class.new(Extendable::ExtensionError) CircularDependencyError = Class.new(Extendable::ExtensionError)
NestingTooDeepError = Class.new(Extendable::ExtensionError) NestingTooDeepError = Class.new(Extendable::ExtensionError)
MAX_NESTING_LEVELS = 10
attr_reader :key attr_reader :key
def initialize(key, context, parent = nil) def initialize(key, context, parent = nil)
...@@ -48,22 +48,22 @@ module Gitlab ...@@ -48,22 +48,22 @@ module Gitlab
if unknown_extension? if unknown_extension?
raise Entry::InvalidExtensionError, raise Entry::InvalidExtensionError,
"Unknown extends key in extended `#{key}`!" "#{key}: unknown `extends` key"
end end
if invalid_base? if invalid_base?
raise Entry::InvalidExtensionError, raise Entry::InvalidExtensionError,
"Invalid base hash in extended `#{key}`!" "#{key}: invalid base hash in `extends`"
end end
if nesting_too_deep? if nesting_too_deep?
raise Entry::NestingTooDeepError, raise Entry::NestingTooDeepError,
"`extends` nesting too deep in `#{key}`!" "#{key}: `extends` nesting too deep"
end end
if circular_dependency? if circular_dependency?
raise Entry::CircularDependencyError, raise Entry::CircularDependencyError,
"Circular dependency detected in extended `#{key}`!" "#{key}: circular dependency detected in `extends`"
end end
@context[key] = base_hash!.deep_merge(value) @context[key] = base_hash!.deep_merge(value)
......
...@@ -126,7 +126,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do ...@@ -126,7 +126,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do
it 'raises an error' do it 'raises an error' do
expect { subject.extend! } expect { subject.extend! }
.to raise_error(StandardError, /Invalid base hash/) .to raise_error(described_class::InvalidExtensionError,
/invalid base hash/)
end end
end end
...@@ -137,7 +138,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do ...@@ -137,7 +138,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do
it 'raises an error' do it 'raises an error' do
expect { subject.extend! } expect { subject.extend! }
.to raise_error(StandardError, /Unknown extends key/) .to raise_error(described_class::InvalidExtensionError,
/unknown `extends` key/)
end end
end end
...@@ -199,7 +201,7 @@ describe Gitlab::Ci::Config::Extendable::Entry do ...@@ -199,7 +201,7 @@ describe Gitlab::Ci::Config::Extendable::Entry do
it 'raises an error' do it 'raises an error' do
expect { subject.extend! } expect { subject.extend! }
.to raise_error(described_class::CircularDependencyError, .to raise_error(described_class::CircularDependencyError,
/Circular dependency detected/) /circular dependency detected/)
end end
end end
......
...@@ -119,7 +119,7 @@ describe Gitlab::Ci::Config do ...@@ -119,7 +119,7 @@ describe Gitlab::Ci::Config do
it 'raises an error' do it 'raises an error' do
expect { config }.to raise_error( expect { config }.to raise_error(
described_class::ConfigError, /Circular dependency detected/ described_class::ConfigError, /circular dependency detected/
) )
end end
end end
......
...@@ -1367,7 +1367,7 @@ module Gitlab ...@@ -1367,7 +1367,7 @@ module Gitlab
expect { Gitlab::Ci::YamlProcessor.new(config) } expect { Gitlab::Ci::YamlProcessor.new(config) }
.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, .to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'Unknown extends key in extended `rspec`!') 'rspec: unknown `extends` key')
end 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