From 06fb31544f2ba67369191565e1373b1df2b2781b Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sat, 7 Sep 2013 20:15:34 +0200 Subject: [PATCH 1/5] Change error handling for gist tag: raise exception --- lib/jekyll/tags/gist.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/tags/gist.rb b/lib/jekyll/tags/gist.rb index d69499af..145a41b4 100644 --- a/lib/jekyll/tags/gist.rb +++ b/lib/jekyll/tags/gist.rb @@ -12,7 +12,15 @@ module Jekyll gist_id, filename = tag_contents[0], tag_contents[1] gist_script_tag(gist_id, filename) else - "Error parsing gist id" + raise SyntaxError.new <<-eos +Syntax error in tag 'gist' while parsing the following markup: + + #{@markup} + +Valid syntax: + for public gists: {% gist 1234567 %} + for private gists: {% gist user/1234567 %} +eos end end From 39c0d125bbb34d42f01b8fbd5ce50d91a6693360 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Tue, 10 Sep 2013 19:25:16 +0200 Subject: [PATCH 2/5] fix tests for new behaviour --- test/test_tags.rb | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/test/test_tags.rb b/test/test_tags.rb index c58c9c7e..6179077e 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -273,22 +273,19 @@ CONTENT end end - context "when invalid" do - setup do - @gist = "mattr-24081a1d93d2898ecf0f" - @filename = "myfile.ext" - content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) - end - should "write script tag with specific file in gist" do - assert_match "Error parsing gist id", @result + assert_raise SyntaxError do + create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end end end @@ -313,7 +310,7 @@ CONTENT end context "with blank gist id" do - setup do + should "raise SyntaxError" do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) - end - should "output error message" do - assert_match "Error parsing gist id", @result + assert_raise SyntaxError do + create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) + end end end context "with invalid gist id" do - setup do + should "raise SyntaxError" do invalid_gist = 'invalid' content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) - end - should "output error message" do - assert_match "Error parsing gist id", @result + assert_raise SyntaxError do + create_post(content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) + end end end end From 72c3bba56a345ecb0c30580b227396599bfeef15 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sat, 7 Sep 2013 20:11:00 +0200 Subject: [PATCH 3/5] Change error handling in 'post_url' tag: raise exception --- lib/jekyll/tags/post_url.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 51b3b605..063e22a4 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -50,9 +50,11 @@ module Jekyll end end - puts "ERROR: post_url: \"#{@orig_post}\" could not be found" + raise ArgumentError.new <<-eos +Could not find post "#{@orig_post}" in tag 'post_url'. - return "#" +Make sure the post exists and the name is correct. +eos end end end From 9409a3d0348a126bd654d98eb7c0246f1e0f6921 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Thu, 19 Sep 2013 14:32:15 +0200 Subject: [PATCH 4/5] raise exceptions in include tag --- lib/jekyll/tags/include.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 2b0d82b4..4d883922 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -72,14 +72,10 @@ eos def render(context) dir = File.join(context.registers[:site].source, INCLUDES_DIR) - if error = validate_dir(dir, context.registers[:site].safe) - return error - end + validate_dir(dir, context.registers[:site].safe) file = File.join(dir, @file) - if error = validate_file(dir, context.registers[:site].safe) - return error - end + validate_file(file, context.registers[:site].safe) partial = Liquid::Template.parse(source(file)) @@ -91,15 +87,15 @@ eos def validate_dir(dir, safe) if File.symlink?(dir) && safe - "Includes directory '#{dir}' cannot be a symlink" + raise IOError.new "Includes directory '#{dir}' cannot be a symlink" end end def validate_file(file, safe) if !File.exists?(file) - "Included file '#{@file}' not found in '#{INCLUDES_DIR}' directory" + raise IOError.new "Included file '#{@file}' not found in '#{INCLUDES_DIR}' directory" elsif File.symlink?(file) && safe - "The included file '#{INCLUDES_DIR}/#{@file}' should not be a symlink" + raise IOError.new "The included file '#{INCLUDES_DIR}/#{@file}' should not be a symlink" end end From 1829c2734a43db457d8f243dcb10a441ff6973e8 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Thu, 19 Sep 2013 23:23:04 +0200 Subject: [PATCH 5/5] 'gist' tag: switch to ArgumentError exception class SyntaxError is reserved for Ruby's internal use. Adjust the tests, including the call to liquid to make it rethrow ArgumentErrors. --- lib/jekyll/tags/gist.rb | 2 +- test/test_tags.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/jekyll/tags/gist.rb b/lib/jekyll/tags/gist.rb index 145a41b4..f4f32880 100644 --- a/lib/jekyll/tags/gist.rb +++ b/lib/jekyll/tags/gist.rb @@ -12,7 +12,7 @@ module Jekyll gist_id, filename = tag_contents[0], tag_contents[1] gist_script_tag(gist_id, filename) else - raise SyntaxError.new <<-eos + raise ArgumentError.new <<-eos Syntax error in tag 'gist' while parsing the following markup: #{@markup} diff --git a/test/test_tags.rb b/test/test_tags.rb index 6179077e..fe16faa5 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -19,7 +19,7 @@ class TestTags < Test::Unit::TestCase payload = { "pygments_prefix" => @converter.pygments_prefix, "pygments_suffix" => @converter.pygments_suffix } - @result = Liquid::Template.parse(content).render(payload, info) + @result = Liquid::Template.parse(content).render!(payload, info) @result = @converter.convert(@result) end @@ -273,7 +273,7 @@ CONTENT end end - should "raise SyntaxError when invalid" do + should "raise ArgumentError when invalid" do @gist = "mattr-24081a1d93d2898ecf0f" @filename = "myfile.ext" content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end end @@ -310,7 +310,7 @@ CONTENT end context "with blank gist id" do - should "raise SyntaxError" do + should "raise ArgumentError" do content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end end end context "with invalid gist id" do - should "raise SyntaxError" do + should "raise ArgumentError" do invalid_gist = 'invalid' content = < 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true}) end end