Skip to content

Commit

Permalink
Better error message on failed convert because of running calibre ins…
Browse files Browse the repository at this point in the history
…tance (janeczku#3100)
  • Loading branch information
OzzieIsaacs committed Jul 11, 2024
1 parent 6996e81 commit 02d2c2b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cps/tasks/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,18 @@ def _convert_calibre(self, file_path, format_old_ext, format_new_ext, has_cover)
'--with-library', library_path]
p = process_open(opf_command, quotes, my_env)
p.wait()
path_tmp_opf = os.path.join(tmp_dir, "metadata_" + str(uuid4()) + ".opf")
with open(path_tmp_opf, 'w') as fd:
copyfileobj(p.stdout, fd)

check = p.returncode
calibre_traceback = p.stderr.readlines()
if check == 0:
path_tmp_opf = os.path.join(tmp_dir, "metadata_" + str(uuid4()) + ".opf")
with open(path_tmp_opf, 'w') as fd:
copyfileobj(p.stdout, fd)
else:
error_message = ""
for ele in calibre_traceback:
if not ele.startswith('Traceback') and not ele.startswith(' File'):
error_message = N_("Calibre failed with error: %(error)s", error=ele)
return check, error_message
quotes = [1, 2, 4, 6]
command = [config.config_converterpath, (file_path + format_old_ext),
(file_path + format_new_ext)]
Expand Down

0 comments on commit 02d2c2b

Please sign in to comment.