Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added exception handling to display a user friendly message when time…

… parse goes wrong
  • Loading branch information...
commit 9c1cf75ce89f9c99504a1f812a0f88fffd0430a1 1 parent 1a9411a
Andrea Schiavini authored plusjade committed
Showing with 6 additions and 1 deletion.
  1. +6 −1 Rakefile
7 Rakefile
@@ -46,7 +46,12 @@ task :post do
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless['posts'])
title = ENV["title"] || "new-post"
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
- date = (Time.parse(ENV['date']) ||'%Y-%m-%d')
+ begin
+ date = (Time.parse(ENV['date']) ||'%Y-%m-%d')
+ rescue Exception => e
+ puts "Error - date format must be YYYY-MM-DD, please check you typed it correctly!"
+ exit -1
+ end
filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}")
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
Please sign in to comment.
Something went wrong with that request. Please try again.