Merge pull request #1098 from mojombo/catch-missing-configs
Crash if a specified config file isn't there
This commit is contained in:
commit
87a3774f2e
|
@ -102,7 +102,10 @@ module Jekyll
|
||||||
def config_files(override)
|
def config_files(override)
|
||||||
# Get configuration from <source>/_config.yml or <source>/<config_file>
|
# Get configuration from <source>/_config.yml or <source>/<config_file>
|
||||||
config_files = override.delete('config')
|
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 = [config_files] unless config_files.is_a? Array
|
||||||
config_files
|
config_files
|
||||||
end
|
end
|
||||||
|
@ -114,9 +117,17 @@ module Jekyll
|
||||||
# Returns this configuration, overridden by the values in the file
|
# Returns this configuration, overridden by the values in the file
|
||||||
def read_config_file(file)
|
def read_config_file(file)
|
||||||
next_config = YAML.safe_load_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
|
Jekyll.logger.info "Configuration file:", file
|
||||||
next_config
|
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
|
end
|
||||||
|
|
||||||
# Public: Read in a list of configuration files and merge with this hash
|
# 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)
|
new_config = read_config_file(config_file)
|
||||||
configuration = configuration.deep_merge(new_config)
|
configuration = configuration.deep_merge(new_config)
|
||||||
end
|
end
|
||||||
rescue SystemCallError
|
rescue ArgumentError => err
|
||||||
# Errno:ENOENT = file not found
|
|
||||||
Jekyll.logger.warn "Configuration file:", "none"
|
|
||||||
rescue => err
|
|
||||||
Jekyll.logger.warn "WARNING:", "Error reading configuration. " +
|
Jekyll.logger.warn "WARNING:", "Error reading configuration. " +
|
||||||
"Using defaults (and options)."
|
"Using defaults (and options)."
|
||||||
$stderr.puts "#{err}"
|
$stderr.puts "#{err}"
|
||||||
|
|
|
@ -82,6 +82,7 @@ class TestConfiguration < Test::Unit::TestCase
|
||||||
context "loading configuration" do
|
context "loading configuration" do
|
||||||
setup do
|
setup do
|
||||||
@path = File.join(Dir.pwd, '_config.yml')
|
@path = File.join(Dir.pwd, '_config.yml')
|
||||||
|
@user_config = File.join(Dir.pwd, "my_config_file.yml")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "fire warning with no _config.yml" do
|
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)
|
mock($stderr).puts("Configuration file: (INVALID) #{@path}".yellow)
|
||||||
assert_equal Jekyll::Configuration::DEFAULTS, Jekyll.configuration({})
|
assert_equal Jekyll::Configuration::DEFAULTS, Jekyll.configuration({})
|
||||||
end
|
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
|
end
|
||||||
context "loading config from external file" do
|
context "loading config from external file" do
|
||||||
setup do
|
setup do
|
||||||
|
|
Loading…
Reference in New Issue