Skip to content

Commit 4d9d5a5

Browse files
committed
Handle non-existent check
1 parent 57abb7f commit 4d9d5a5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/jekyll-pre-commit/runner.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ def run(site, staged_files)
2828
end
2929

3030
site.config["pre-commit"].each do |c|
31-
o = Object.const_get("Jekyll::PreCommit::Check::" + c["check"]).new
31+
begin
32+
o = Object.const_get("Jekyll::PreCommit::Check::" + c["check"]).new
33+
rescue
34+
result[:ok] = false
35+
# Skip any other messages so the user focuses on this.
36+
result[:message] = ["The check #{c["check"]} does not exist! Please fix your configuration."]
37+
break
38+
end
3239
r = o.Check(staged_posts, not_staged_posts, site, c)
3340
if !r[:ok]
3441
result[:ok] = false

spec/jekyll-pre-commit_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,15 @@
122122
expect(result[:messages]).to match_array([])
123123
end
124124
end
125+
126+
context "with a check that doesn't exist" do
127+
pre_commit_config = {"check" => "Garbage"}
128+
let(:site) { build_site({ 'pre-commit' => [pre_commit_config] }) }
129+
130+
it "fails with non-existent check message" do
131+
result = runner.run(site, ["spec/fixtures/_posts/2017-01-06-no-description.md"])
132+
expect(result[:ok]).to eql(false)
133+
expect(result[:message]).to match_array(["The check Garbage does not exist! Please fix your configuration."])
134+
end
135+
end
125136
end

0 commit comments

Comments
 (0)