Skip to content

remove exit in lib/aozora2html; use exit in bin/aozora2html #113

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

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ Layout/LineLength:
Lint/EmptyClass:
AllowComments: true

Lint/InheritException:
Enabled: false

Metrics/AbcSize:
Enabled: true
Max: 260.05
Expand Down
2 changes: 2 additions & 0 deletions bin/aozora2html
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ Dir.mktmpdir do |dir|
output = File.read(dest_file)
print output
end
rescue Aozora2Html::FatalError
exit(2)
end
2 changes: 1 addition & 1 deletion lib/aozora2html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def process
rescue Aozora2Html::Error => e
puts e.message(line_number)
if e.is_a?(Aozora2Html::Error)
exit(2)
raise Aozora2Html::FatalError
end
end
tail_output # final call
Expand Down
4 changes: 4 additions & 0 deletions lib/aozora2html/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ def message(line = 0)
I18n.t(:error_stop, line, @message)
end
end

# Aozora2Htmlクラス内でexitする代わりに例外をあげるためのfatal error用クラス
class FatalError < Exception
end
end
6 changes: 2 additions & 4 deletions lib/jstream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class Jstream
CRLF = CR + LF

# 初期化と同時に、いったん最初の行をscanして、改行コードがCR+LFかどうか調べる。
# CR+LFでない場合はエラーメッセージを出力してexitする(!)
#
# TODO: 将来的にはさすがにexitまではしないよう、仕様を変更する?
# CR+LFでない場合はエラーメッセージを出力して、例外Aozora2Html::FatalErrorを上げる
def initialize(file_io)
@line = 0
@current_char = nil
Expand All @@ -30,7 +28,7 @@ def initialize(file_io)
rescue Aozora2Html::Error => e
puts e.message(1)
if e.is_a?(Aozora2Html::Error)
exit(2)
raise Aozora2Html::FatalError
end
ensure
@file.rewind
Expand Down
2 changes: 1 addition & 1 deletion test/test_jstream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_new_error
orig_stdout = $stdout
out = StringIO.new
$stdout = out
assert_raises(SystemExit) do
assert_raises(Aozora2Html::FatalError) do
Jstream.new(strio)
end
$stdout = orig_stdout
Expand Down