View Single Post
Old 03-20-2016, 02:48 PM   #1
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 7,105
Karma: 92190133
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
Question about ConversionUserFeedBack

I am working on a calibre Conversion Output plugin and have come across something that I don't understand so I am asking about it here.

Unfortunately, the plugin is expected to fail to convert some books and I want to notify the user of the reason why when this occurs. To do this I am raising a ConversionUserFeedBack exception to provide the error message. I used this test code to always simulate a conversion error:

Code:
    def convert(self, oeb_book, output, input_plugin, opts, log):
        import calibre.ebooks.conversion
        raise calibre.ebooks.conversion.ConversionUserFeedBack("Conversion failed", "test", level="error")
When I start a conversion that uses this output plugin this works properly for most books and pops up a dialog box with a title of Conversion failed and a message of test. The end of the job log shows the exception I raised as expected:

Code:
Python function terminated unexpectedly
  {"title": "Conversion failed", "msg": "test", "det_msg": "", "level": "error"} (Error Code: 1)
Traceback (most recent call last):
  File "site.py", line 132, in main
  File "site.py", line 109, in run_entry_point
  File "site-packages\calibre\utils\ipc\worker.py", line 190, in main
  File "site-packages\calibre\gui2\convert\gui_conversion.py", line 31, in gui_convert_override
  File "site-packages\calibre\gui2\convert\gui_conversion.py", line 25, in gui_convert
  File "site-packages\calibre\ebooks\conversion\plumber.py", line 1219, in run
  File "calibre_plugins.kfx_output.__init__", line 49, in convert
calibre.ebooks.conversion.ConversionUserFeedBack: {"title": "Conversion failed", "msg": "test", "det_msg": "", "level": "error"}
However, this does not work for a small subset of books and I can't figure out why. For these books it consistently fails to give the expected error dialog. Instead it pops up a generic conversion error dialog. Looking at the end of the conversion job log for those book I see the following:

Code:
[Python function terminated unexpectedly
  {"title": "Conversion failed", "det_msg": "", "level": "error", "msg": "test"} (Error Code: 1)
Traceback (most recent call last):
  File "site.py", line 132, in main
  File "site.py", line 109, in run_entry_point
  File "site-packages\calibre\utils\ipc\worker.py", line 190, in main
  File "site-packages\calibre\gui2\convert\gui_conversion.py", line 31, in gui_convert_override
  File "site-packages\calibre\gui2\convert\gui_conversion.py", line 25, in gui_convert
  File "site-packages\calibre\ebooks\conversion\plumber.py", line 1219, in run
  File "calibre_plugins.kfx_output.__init__", line 49, in convert
ConversionUserFeedBack: {"title": "Conversion failed", "det_msg": "", "level": "error", "msg": "test"}
Note that the exception shows as ConversionUserFeedBack instead of calibre.ebooks.conversion.ConversionUserFeedBack. This causes the problem since the code in calibre/gui2/ui.py is looking for only the longer string.

I cannot figure out why the exception is sometimes reported differently in the log. Any help would be appreciated.
jhowell is offline   Reply With Quote