TXT Output crashes when --max-line-length option is set

Bug #1941992 reported by Gregory Khvatsky
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Unassigned

Bug Description

When trying ebook-convert (from calibre 5.26.0 on Linux) with TXT output and --max-line-length option set to more than 25, e.g.

ebook-convert d_ch.fb2 text.txt --max-line-length 70

The command crashes with the following error:

.....
Converting XHTML to TXT...
Traceback (most recent call last):
  File "runpy.py", line 194, in _run_module_as_main
  File "runpy.py", line 87, in _run_code
  File "site.py", line 45, in <module>
  File "site.py", line 41, in main
  File "calibre/ebooks/conversion/cli.py", line 401, in main
  File "calibre/ebooks/conversion/plumber.py", line 1271, in run
  File "calibre/ebooks/conversion/plugins/txt_output.py", line 100, in convert
  File "calibre/ebooks/txt/txtml.py", line 65, in extract_content
  File "calibre/ebooks/txt/txtml.py", line 86, in mlize_spine
  File "calibre/ebooks/txt/txtml.py", line 160, in cleanup_text
TypeError: slice indices must be integers or None or have an __index__ method

This is most likely due to the fact that for some reason, in the function cleanup_text, the type of self.opts.max_line_length is float, which, when passed to line.rfind(...) on line 160, causes the error. This behavior of rfind can be reproduced by running something like

"aaaa aaaa".rfind(" ", 0, 1.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method

In a Python console.

Included is a patch that fixes this by forcibly converting self.opts.max_line_length to an int, although I am not sure whether it broke something else or not.

Tags: txt-output
Revision history for this message
Gregory Khvatsky (gregkh1996) wrote :
description: updated
Revision history for this message
Kovid Goyal (kovid) wrote : Fixed in master

Fixed in branch master. The fix will be in the next release. calibre is usually released every alternate Friday.

 status fixreleased

Changed in calibre:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.