From f8c19df79a1309597f16ed2c9a6392e9b55968c3 Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Wed, 30 Jul 2014 12:48:29 -0700 Subject: [PATCH] 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