Skip to content

Commit

Permalink
raise explicit error if file fails to derive
Browse files Browse the repository at this point in the history
This provides more visibility if further OOM errors cause the process to
fail silently
  • Loading branch information
bkiahstroud committed Oct 1, 2024
1 parent ac55d98 commit de44601
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/space_stone/ocrcelot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def ocr
FileUtils.mkdir_p(File.dirname(hocr_path))
cmd = "#{OCR_CMD} '#{mono_path}' #{hocr_path} hocr"
run(cmd)
puts "remove tmp files:"
puts %x{rm -v #{mono_path}}
"#{hocr_path}.hocr"
file_path = "#{hocr_path}.hocr"
raise 'generating OCR file failed' unless File.exist?(file_path)
puts 'remove tmp files:'
puts `rm -v #{mono_path}`
file_path
end

def prep_file
Expand All @@ -34,6 +36,7 @@ def prep_file
opts = '-depth 1 -monochrome -compress Group4 -type bilevel'
cmd = "convert '#{path}' #{opts} '#{out_path}'"
run(cmd)
raise 'generating TIFF file failed' unless File.exist?(out_path)
out_path
end

Expand Down
1 change: 1 addition & 0 deletions lib/space_stone/thumbnail_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def derive
cmd = "convert #{path} -thumbnail '200x150>' -flatten #{thumbnail_path}"
puts cmd
`#{cmd}`
raise 'generating thumbnail failed' unless File.exist?(thumbnail_path)
thumbnail_path
end
end
Expand Down

0 comments on commit de44601

Please sign in to comment.