Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ファイル存在チェックの強化 #1727

Merged
merged 10 commits into from
Sep 5, 2021
8 changes: 4 additions & 4 deletions lib/review/epubmaker/epubcommon.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# = epubcommon.rb -- super class for EPUBv2 and EPUBv3
#
# Copyright (c) 2010-2019 Kenshi Muto and Masayoshi Takahashi
# Copyright (c) 2010-2021 Kenshi Muto and Masayoshi Takahashi
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -70,7 +70,7 @@ def opf_coverimage
item = contents.find { |content| content.coverimage?(config['coverimage']) }

unless item
raise "coverimage #{config['coverimage']} not found. Abort."
raise ApplicationError, "coverimage #{config['coverimage']} not found. Abort."
end

%Q( <meta name="cover" content="#{item.id}"/>\n)
Expand Down Expand Up @@ -107,7 +107,7 @@ def cover

if config['coverimage']
@coverimage_src = coverimage
raise "coverimage #{config['coverimage']} not found. Abort." unless @coverimage_src
raise ApplicationError, "coverimage #{config['coverimage']} not found. Abort." unless @coverimage_src
end
@body = ReVIEW::Template.generate(path: './html/_cover.html.erb', binding: binding)

Expand Down Expand Up @@ -338,7 +338,7 @@ def produce_write_common(basedir, tmpdir)

fname = "#{basedir}/#{item.file}"
unless File.exist?(fname)
raise "#{fname} is not found."
raise ApplicationError, "#{fname} is not found."
end

FileUtils.mkdir_p(File.dirname("#{tmpdir}/OEBPS/#{item.file}"))
Expand Down
16 changes: 13 additions & 3 deletions lib/review/pdfmaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,16 @@ def copy_images(from, to)
end

def make_custom_page(file)
if file.nil?
return nil
end

file_sty = file.to_s.sub(/\.[^.]+\Z/, '.tex')
if File.exist?(file_sty)
return File.read(file_sty)
File.read(file_sty)
else
raise ReVIEW::ConfigError, "File #{file} is not found."
end

nil
end

def join_with_separator(value, sep)
Expand Down Expand Up @@ -442,6 +446,10 @@ def erb_config
end
end

if @config['coverimage'] && !File.exist?(File.join(@config['imagedir'], @config['coverimage']))
raise ReVIEW::ConfigError, "coverimage #{@config['coverimage']} is not found."
end

@locale_latex = {}
part_tuple = I18n.get('part').split(/%[A-Za-z]{1,3}/, 2)
chapter_tuple = I18n.get('chapter').split(/%[A-Za-z]{1,3}/, 2)
Expand Down Expand Up @@ -471,6 +479,8 @@ def latex_config
result << "%% END: config-local.tex.erb\n"
end
result
rescue StandardError => e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rescue StandardError => e
rescue ApplicationError => e

ReVIEW::ConfigError等を拾うのであれば ApplicationError でできます(何でもStandardErrorで握りつぶしてしまうのは良くなさそうなので)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERBのbindでエラーが出たときにSyntaxError, ZeroDivisionErrorなど予想がつかない生の例外がきてしまうんですよね。ApplicationErrorで拾えなくて困っています。

error! "template or configuration error: #{e.message}"
end

def template_content
Expand Down