Put errors/exceptions into Jekyll::Errors module

This commit is contained in:
Parker Moore 2014-07-12 13:47:59 -07:00
parent a97ae67552
commit c7cc36abdb
13 changed files with 165 additions and 146 deletions

View File

@ -51,7 +51,7 @@ module Jekyll
# Returns nothing
def process_site(site)
site.process
rescue Jekyll::FatalException => e
rescue Jekyll::Errors::FatalException => e
Jekyll.logger.error "ERROR:", "YOUR SITE COULD NOT BE BUILT:"
Jekyll.logger.error "", "------------------------------------"
Jekyll.logger.error "", e.message

View File

@ -20,13 +20,32 @@ module Jekyll
self.class.const_get(@config['markdown']).new(@config)
else
Jekyll.logger.error "Invalid Markdown Processor:", "#{@config['markdown']}"
Jekyll.logger.error "", "Valid options are [ maruku | rdiscount | kramdown | redcarpet ]"
raise FatalException, "Invalid Markdown Processor: #{@config['markdown']}"
Jekyll.logger.error "", "Valid options are [ #{valid_processors.join(" | ")} ]"
raise Errors::FatalException, "Invalid Markdown Processor: #{@config['markdown']}"
end
end
@setup = true
end
def valid_processors
%w[
maruku
rdiscount
kramdown
redcarpet
] + third_party_processors
end
def third_party_processors
self.class.constants - %w[
KramdownParser
MarukuParser
RDiscountParser
RedcarpetParser
PRIORITIES
].map(&:to_sym)
end
def matches(ext)
rgx = '^\.(' + @config['markdown_ext'].gsub(',','|') +')$'
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)

View File

@ -8,7 +8,7 @@ module Jekyll
rescue LoadError
STDERR.puts 'You are missing a library required for Markdown. Please run:'
STDERR.puts ' $ [sudo] gem install kramdown'
raise FatalException.new("Missing dependency: kramdown")
raise Errors::FatalException.new("Missing dependency: kramdown")
end
def convert(content)

View File

@ -15,7 +15,7 @@ module Jekyll
rescue LoadError
STDERR.puts 'You are missing a library required for Markdown. Please run:'
STDERR.puts ' $ [sudo] gem install maruku'
raise FatalException.new("Missing dependency: maruku")
raise Errors::FatalException.new("Missing dependency: maruku")
end
def load_divs_library

View File

@ -13,7 +13,7 @@ module Jekyll
rescue LoadError
STDERR.puts 'You are missing a library required for Textile. Please run:'
STDERR.puts ' $ [sudo] gem install RedCloth'
raise FatalException.new("Missing dependency: RedCloth")
raise Errors::FatalException.new("Missing dependency: RedCloth")
end
def matches(ext)

View File

@ -1,5 +1,8 @@
module Jekyll
class FatalException < StandardError
module Errors
class FatalException < RuntimeError
end
class MissingDependencyException < FatalException
end
end

View File

@ -1,4 +1,3 @@
require 'jekyll/convertible'
require 'forwardable'
module Jekyll

View File

@ -1,5 +1,4 @@
module Jekyll
class Configuration
# This class handles custom defaults for YAML frontmatter settings.
# These are set in _config.yml and apply both to internal use (e.g. layout)
# and the data available to liquid.
@ -145,4 +144,3 @@ module Jekyll
end
end
end
end

View File

@ -166,7 +166,7 @@ module Jekyll
path = File.join(@dir || "", name)
msg = "Post '#{path}' does not have a valid date.\n"
msg << "Fix the date, or exclude the file or directory from being processed"
raise FatalException.new(msg)
raise Errors::FatalException.new(msg)
end
# The generated directory into which the post will be placed

View File

@ -80,7 +80,7 @@ module Jekyll
dest_pathname = Pathname.new(dest)
Pathname.new(source).ascend do |path|
if path == dest_pathname
raise FatalException.new "Destination directory cannot be or contain the Source directory."
raise Errors::FatalException.new "Destination directory cannot be or contain the Source directory."
end
end
end
@ -443,7 +443,7 @@ module Jekyll
end
def frontmatter_defaults
@frontmatter_defaults ||= Configuration::FrontmatterDefaults.new(self)
@frontmatter_defaults ||= FrontmatterDefaults.new(self)
end
private

View File

@ -44,7 +44,7 @@ class TestCommand < Test::Unit::TestCase
context "when fatal error occurs" do
should "exit with non-zero error code" do
site = Object.new
stub(site).process { raise Jekyll::FatalException }
stub(site).process { raise Jekyll::Errors::FatalException }
error = assert_raise(SystemExit) { Command.process_site(site) }
assert_not_equal 0, error.status
end

View File

@ -83,7 +83,7 @@ class TestPost < Test::Unit::TestCase
end
should "raise a good error on invalid post date" do
assert_raise Jekyll::FatalException do
assert_raise Jekyll::Errors::FatalException do
@post.process("2009-27-03-foo-bar.textile")
end
end

View File

@ -225,7 +225,7 @@ class TestSite < Test::Unit::TestCase
Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => source_dir})
end
assert_raise Jekyll::FatalException do
assert_raise Jekyll::Errors::FatalException do
site = Site.new(Jekyll.configuration)
end
end
@ -235,7 +235,7 @@ class TestSite < Test::Unit::TestCase
Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => File.join(source_dir, "..")})
end
assert_raise Jekyll::FatalException do
assert_raise Jekyll::Errors::FatalException do
site = Site.new(Jekyll.configuration)
end
end
@ -332,7 +332,7 @@ class TestSite < Test::Unit::TestCase
bad_processor = "Custom::Markdown"
s = Site.new(Jekyll.configuration.merge({ 'markdown' => bad_processor }))
assert_raise Jekyll::FatalException do
assert_raise Jekyll::Errors::FatalException do
s.process
end
@ -352,7 +352,7 @@ class TestSite < Test::Unit::TestCase
should 'throw FatalException at process time' do
bad_processor = 'not a processor name'
s = Site.new(Jekyll.configuration.merge({ 'markdown' => bad_processor }))
assert_raise Jekyll::FatalException do
assert_raise Jekyll::Errors::FatalException do
s.process
end
end