Skip to content

Commit

Permalink
remove exit in lib/aozora2html; use exit in bin/aozora2html
Browse files Browse the repository at this point in the history
  • Loading branch information
takahashim committed Jan 31, 2024
1 parent 50e0830 commit 6f7eab8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
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
2 changes: 1 addition & 1 deletion lib/jstream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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

0 comments on commit 6f7eab8

Please sign in to comment.