Skip to content

Commit

Permalink
check yaml existence and parse error. Closes #958
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Feb 26, 2018
1 parent 5f9155b commit 1545145
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 13 deletions.
21 changes: 18 additions & 3 deletions bin/review-compile
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,26 @@ def _main
end

begin
loader = ReVIEW::YAMLLoader.new
if config['yaml']
config.deep_merge!(loader.load_file(config['yaml']))
unless File.exist?(config['yaml'])
@logger.error "#{config['yaml']} not found."
exit 1
end
begin
config.deep_merge!(YAML.load_file(config['yaml']))
rescue => e
@logger.error 'yaml error'
@logger.error e.message
exit 1
end
elsif File.exist?(DEFAULT_CONFIG_FILENAME)
config.deep_merge!(loader.load_file(DEFAULT_CONFIG_FILENAME))
begin
config.deep_merge!(YAML.load_file(DEFAULT_CONFIG_FILENAME))
rescue => e
@logger.error 'yaml error'
@logger.error e.message
exit 1
end
end

config['builder'] = target
Expand Down
7 changes: 6 additions & 1 deletion bin/review-epubmaker
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ rescue OptionParser::ParseError => err
exit 1
end

if ARGV.size < 1 || !File.exist?(ARGV[0])
if ARGV.size < 1
puts opts.help
exit 1
end

unless File.exist?(ARGV[0])
@logger.error "#{ARGV[0]} not found."
exit 1
end

yaml_file = ARGV[0]
bookname = ARGV[1]
rv.produce(yaml_file, bookname)
11 changes: 9 additions & 2 deletions lib/review/epubmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@ def log(s)
end

def load_yaml(yamlfile)
loader = ReVIEW::YAMLLoader.new
@config = ReVIEW::Configure.values.deep_merge(loader.load_file(yamlfile))
@config = ReVIEW::Configure.values
begin
@config.deep_merge!(YAML.load_file(yamlfile))
rescue => e
@logger.error 'yaml error'
@logger.error e.message
exit 1
end

@producer = Producer.new(@config)
@producer.load(yamlfile)
@config = @producer.config
Expand Down
16 changes: 13 additions & 3 deletions lib/review/pdfmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,20 @@ def execute(*args)
@config = ReVIEW::Configure.values
@config.maker = 'pdfmaker'
cmd_config, yamlfile = parse_opts(args)
loader = ReVIEW::YAMLLoader.new
@config.deep_merge!(loader.load_file(yamlfile))
unless File.exist?(yamlfile)
@logger.error "#{yamlfile} not found."
exit 1
end

begin
@config.deep_merge!(YAML.load_file(yamlfile))
rescue => e
@logger.error 'yaml error'
@logger.error e.message
exit 1
end
# YAML configs will be overridden by command line options.
@config.merge!(cmd_config)
@config.deep_merge!(cmd_config)
I18n.setup(@config['language'])
@basedir = File.dirname(yamlfile)
@basehookdir = File.absolute_path(File.dirname(yamlfile))
Expand Down
14 changes: 12 additions & 2 deletions lib/review/textmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,20 @@ def execute(*args)
@config = ReVIEW::Configure.values
@config.maker = 'textmaker'
cmd_config, yamlfile = parse_opts(args)
unless File.exist?(yamlfile)
@logger.error "#{yamlfile} not found."
exit 1
end

@config.merge!(YAML.load_file(yamlfile))
begin
@config.deep_merge!(YAML.load_file(yamlfile))
rescue => e
@logger.error 'yaml error'
@logger.error e.message
exit 1
end
# YAML configs will be overridden by command line options.
@config.merge!(cmd_config)
@config.deep_merge!(cmd_config)
I18n.setup(@config['language'])
generate_text_files(yamlfile)
end
Expand Down
14 changes: 12 additions & 2 deletions lib/review/webmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,20 @@ def execute(*args)
@config = ReVIEW::Configure.values
@config.maker = 'webmaker'
cmd_config, yamlfile = parse_opts(args)
unless File.exist?(yamlfile)
@logger.error "#{yamlfile} not found."
exit 1
end

@config.merge!(YAML.load_file(yamlfile))
begin
@config.deep_merge!(YAML.load_file(yamlfile))
rescue => e
@logger.error 'yaml error'
@logger.error e.message
exit 1
end
# YAML configs will be overridden by command line options.
@config.merge!(cmd_config)
@config.deep_merge!(cmd_config)
@config['htmlext'] = 'html'
I18n.setup(@config['language'])
generate_html_files(yamlfile)
Expand Down

0 comments on commit 1545145

Please sign in to comment.