Commit 66c92029 authored by Kamil Trzciński's avatar Kamil Trzciński
Browse files

Merge branch '41209-ci-linter-fails-on-gitlab-ci-blob-viewer' into 'master'

Resolve "CI linter fails to work"

Closes #41209

See merge request gitlab-org/gitlab-ce!16922
......@@ -16,10 +16,7 @@
@builds = @config_processor.builds
@jobs = @config_processor.jobs
end
rescue
@error = 'Undefined error'
@status = false
ensure
render :show
end
end
......
......@@ -394,7 +394,7 @@
@config_processor ||= begin
Gitlab::Ci::YamlProcessor.new(ci_yaml_file)
rescue Gitlab::Ci::YamlProcessor::ValidationError, Psych::SyntaxError => e
rescue Gitlab::Ci::YamlProcessor::ValidationError => e
self.yaml_errors = e.message
nil
rescue
......
---
title: 'Handle all Psych YAML parser exceptions (fixes #41209)'
merge_request:
author:
type: fixed
......@@ -6,6 +6,8 @@
def initialize(config)
@config = YAML.safe_load(config, [Symbol], [], true)
rescue Psych::Exception => e
raise FormatError, e.message
end
def valid?
......
......@@ -85,7 +85,7 @@
begin
Gitlab::Ci::YamlProcessor.new(content)
nil
rescue ValidationError, Psych::SyntaxError => e
rescue ValidationError => e
e.message
end
end
......
......@@ -38,6 +38,16 @@
end
end
context 'when there is an unknown alias' do
let(:yml) { 'steps: *bad_alias' }
describe '#initialize' do
it 'raises FormatError' do
expect { loader }.to raise_error(Gitlab::Ci::Config::Loader::FormatError, 'Unknown alias: bad_alias')
end
end
end
context 'when yaml config is empty' do
let(:yml) { '' }
......
......@@ -1394,7 +1394,9 @@
describe "Error handling" do
it "fails to parse YAML" do
expect {Gitlab::Ci::YamlProcessor.new("invalid: yaml: test")}.to raise_error(Psych::SyntaxError)
expect do
Gitlab::Ci::YamlProcessor.new("invalid: yaml: test")
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError)
end
it "indicates that object is invalid" do
......@@ -1398,7 +1400,9 @@
end
it "indicates that object is invalid" do
expect {Gitlab::Ci::YamlProcessor.new("invalid_yaml")}.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError)
expect do
Gitlab::Ci::YamlProcessor.new("invalid_yaml")
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError)
end
it "returns errors if tags parameter is invalid" do
......@@ -1688,7 +1692,5 @@
end
describe "#validation_message" do
context "when the YAML could not be parsed" do
it "returns an error about invalid configutaion" do
content = YAML.dump("invalid: yaml: test")
subject { Gitlab::Ci::YamlProcessor.validation_message(content) }
......@@ -1694,7 +1696,8 @@
expect(Gitlab::Ci::YamlProcessor.validation_message(content))
.to eq "Invalid configuration format"
end
context "when the YAML could not be parsed" do
let(:content) { YAML.dump("invalid: yaml: test") }
it { is_expected.to eq "Invalid configuration format" }
end
context "when the tags parameter is invalid" do
......@@ -1698,6 +1701,5 @@
end
context "when the tags parameter is invalid" do
it "returns an error about invalid tags" do
content = YAML.dump({ rspec: { script: "test", tags: "mysql" } })
let(:content) { YAML.dump({ rspec: { script: "test", tags: "mysql" } }) }
......@@ -1703,7 +1705,5 @@
expect(Gitlab::Ci::YamlProcessor.validation_message(content))
.to eq "jobs:rspec tags should be an array of strings"
end
it { is_expected.to eq "jobs:rspec tags should be an array of strings" }
end
context "when YAML content is empty" do
......@@ -1707,10 +1707,15 @@
end
context "when YAML content is empty" do
it "returns an error about missing content" do
expect(Gitlab::Ci::YamlProcessor.validation_message(''))
.to eq "Please provide content of .gitlab-ci.yml"
end
let(:content) { '' }
it { is_expected.to eq "Please provide content of .gitlab-ci.yml" }
end
context 'when the YAML contains an unknown alias' do
let(:content) { 'steps: *bad_alias' }
it { is_expected.to eq "Unknown alias: bad_alias" }
end
context "when the YAML is valid" do
......@@ -1714,6 +1719,5 @@
end
context "when the YAML is valid" do
it "does not return any errors" do
content = File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
let(:content) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
......@@ -1719,6 +1723,5 @@
expect(Gitlab::Ci::YamlProcessor.validation_message(content)).to be_nil
end
it { is_expected.to be_nil }
end
end
......
Supports Markdown
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