gitlab-org--gitlab-foss/lib/gitlab/ci/config/loader.rb
Dylan Griffith 66d41d2c22 Handle all YAML parser exceptions in .gitlab-ci.yml (fixes #41209)
- Move the exception handling as close to the source as possible to
avoid leaking Psych ahstraction
- Also remove unnecessary rescue all statement from LintsController.
This should not be necessary anymore since any YAML errors should all be
caught by the #validation_message method.
2018-02-07 10:09:01 +11:00

27 lines
552 B
Ruby

module Gitlab
module Ci
class Config
class Loader
FormatError = Class.new(StandardError)
def initialize(config)
@config = YAML.safe_load(config, [Symbol], [], true)
rescue Psych::Exception => e
raise FormatError, e.message
end
def valid?
@config.is_a?(Hash)
end
def load!
unless valid?
raise FormatError, 'Invalid configuration format'
end
@config.deep_symbolize_keys
end
end
end
end
end