From f8c19df79a1309597f16ed2c9a6392e9b55968c3 Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Wed, 30 Jul 2014 12:48:29 -0700 Subject: [PATCH 1/2] Add friendly error message for invalid dates Catch the `ArgumentError` when parsing dates from the YAML front matter --- lib/jekyll/post.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index f92e75ee..510c8858 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -61,7 +61,14 @@ module Jekyll end if data.key?('date') - self.date = Time.parse(data["date"].to_s) + begin + self.date = Time.parse(data["date"].to_s) + rescue ArgumentError + path = File.join(@dir || "", name) + msg = "Post '#{path}' does not have a valid date in the YAML front matter.\n" + msg << "Fix the date, or exclude the file or directory from being processed" + raise Errors::FatalException.new(msg) + end end populate_categories From 989d5d357b5a602e8fd0ab0e0c4cea126ff80ddd Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Wed, 30 Jul 2014 12:50:31 -0700 Subject: [PATCH 2/2] Use `relative_path` in error message instead of `path` --- lib/jekyll/post.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 510c8858..2db21fee 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -65,7 +65,7 @@ module Jekyll self.date = Time.parse(data["date"].to_s) rescue ArgumentError path = File.join(@dir || "", name) - msg = "Post '#{path}' does not have a valid date in the YAML front matter.\n" + msg = "Post '#{relative_path}' does not have a valid date in the YAML front matter.\n" msg << "Fix the date, or exclude the file or directory from being processed" raise Errors::FatalException.new(msg) end @@ -173,7 +173,7 @@ module Jekyll self.ext = ext rescue ArgumentError path = File.join(@dir || "", name) - msg = "Post '#{path}' does not have a valid date.\n" + msg = "Post '#{relative_path}' does not have a valid date.\n" msg << "Fix the date, or exclude the file or directory from being processed" raise Errors::FatalException.new(msg) end