diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index c428c1a6..5b5dda4b 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -102,7 +102,10 @@ module Jekyll def config_files(override) # Get configuration from /_config.yml or / config_files = override.delete('config') - config_files = File.join(source(override), "_config.yml") if config_files.to_s.empty? + if config_files.to_s.empty? + config_files = File.join(source(override), "_config.yml") + @default_config_file = true + end config_files = [config_files] unless config_files.is_a? Array config_files end @@ -114,9 +117,17 @@ module Jekyll # Returns this configuration, overridden by the values in the file def read_config_file(file) next_config = YAML.safe_load_file(file) - raise "Configuration file: (INVALID) #{file}".yellow if !next_config.is_a?(Hash) + raise ArgumentError.new("Configuration file: (INVALID) #{file}".yellow) if !next_config.is_a?(Hash) Jekyll.logger.info "Configuration file:", file next_config + rescue SystemCallError + if @default_config_file + Jekyll.logger.warn "Configuration file:", "none" + {} + else + Jekyll.logger.error "Fatal:", "The configuration file '#{file}' could not be found." + raise LoadError + end end # Public: Read in a list of configuration files and merge with this hash @@ -133,10 +144,7 @@ module Jekyll new_config = read_config_file(config_file) configuration = configuration.deep_merge(new_config) end - rescue SystemCallError - # Errno:ENOENT = file not found - Jekyll.logger.warn "Configuration file:", "none" - rescue => err + rescue ArgumentError => err Jekyll.logger.warn "WARNING:", "Error reading configuration. " + "Using defaults (and options)." $stderr.puts "#{err}" diff --git a/test/test_configuration.rb b/test/test_configuration.rb index 0f197643..0e6372b0 100644 --- a/test/test_configuration.rb +++ b/test/test_configuration.rb @@ -82,6 +82,7 @@ class TestConfiguration < Test::Unit::TestCase context "loading configuration" do setup do @path = File.join(Dir.pwd, '_config.yml') + @user_config = File.join(Dir.pwd, "my_config_file.yml") end should "fire warning with no _config.yml" do @@ -102,6 +103,14 @@ class TestConfiguration < Test::Unit::TestCase mock($stderr).puts("Configuration file: (INVALID) #{@path}".yellow) assert_equal Jekyll::Configuration::DEFAULTS, Jekyll.configuration({}) end + + should "fire warning when user-specified config file isn't there" do + mock(YAML).safe_load_file(@user_config) { raise SystemCallError, "No such file or directory - #{@user_config}" } + mock($stderr).puts(("Fatal: ".rjust(20) + "The configuration file '#{@user_config}' could not be found.").red) + assert_raises LoadError do + Jekyll.configuration({'config' => [@user_config]}) + end + end end context "loading config from external file" do setup do