Move new exception catching for metadata errors

This commit is contained in:
Jim Miller 2024-03-05 08:04:22 -06:00
parent 7263f4120c
commit f21f039b3a
2 changed files with 40 additions and 40 deletions

View file

@ -15,7 +15,6 @@ logger = logging.getLogger(__name__)
from datetime import datetime from datetime import datetime
import traceback, sys
from PyQt5 import QtWidgets as QtGui from PyQt5 import QtWidgets as QtGui
from PyQt5 import QtCore from PyQt5 import QtCore
@ -38,7 +37,6 @@ except:
from calibre.gui2 import gprefs from calibre.gui2 import gprefs
show_download_options = 'fff:add new/update dialogs:show_download_options' show_download_options = 'fff:add new/update dialogs:show_download_options'
from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.dialogs.confirm_delete import confirm
from calibre.gui2 import error_dialog
from calibre.gui2.complete2 import EditWithComplete from calibre.gui2.complete2 import EditWithComplete
from fanficfare.six import text_type as unicode, ensure_text from fanficfare.six import text_type as unicode, ensure_text
@ -726,12 +724,6 @@ class _LoopProgressDialog(QProgressDialog):
book['status']=_("Error") book['status']=_("Error")
book['comment']=unicode(e) book['comment']=unicode(e)
logger.error("Exception: %s:%s"%(book,book['comment']),exc_info=True) logger.error("Exception: %s:%s"%(book,book['comment']),exc_info=True)
det_msg = "".join(traceback.format_exception(*sys.exc_info())) # +"\n"+_("Story Details:")+pretty_book(book)
error_dialog(self.gui,
_("Error Updating Metadata"),
"<p>"+_("An error has occurred while FanFicFare was updating calibre's metadata for <a href='%s'>%s</a>.")%(book['url'],book['title'])+"</p>",
det_msg=det_msg,
show=True)
self.updateStatus() self.updateStatus()
self.i += 1 self.i += 1

View file

@ -1797,43 +1797,51 @@ class FanFicFarePlugin(InterfaceAction):
'bgmeta':False}, 'bgmeta':False},
errorcol_label=None, errorcol_label=None,
lastcheckedcol_label=None): lastcheckedcol_label=None):
try:
if options.get('add_tag',False):
book['tags'].extend(options.get('add_tag').split(','))
if options.get('add_tag',False): self.update_error_column_loop(book,db,errorcol_label,lastcheckedcol_label)
book['tags'].extend(options.get('add_tag').split(','))
self.update_error_column_loop(book,db,errorcol_label,lastcheckedcol_label) if not book['good']:
return # on error, only update errorcol
if not book['good']: logger.debug("add/update %s %s id(%s)"%(book['title'],book['url'],book['calibre_id']))
return # on error, only update errorcol mi = self.make_mi_from_book(book)
logger.debug("add/update %s %s id(%s)"%(book['title'],book['url'],book['calibre_id'])) if book['collision'] not in (CALIBREONLY, CALIBREONLYSAVECOL):
mi = self.make_mi_from_book(book) new_book = book['calibre_id'] is None
self.add_book_or_update_format(book,options,prefs,mi)
if new_book:
## For failed chapters. Didn't have calibre_id before
## add_book_or_update_format
self.update_error_column_loop(book,db,errorcol_label,lastcheckedcol_label)
if book['collision'] not in (CALIBREONLY, CALIBREONLYSAVECOL): if book['collision'] in (CALIBREONLY, CALIBREONLYSAVECOL) or \
new_book = book['calibre_id'] is None ( (options['updatemeta'] or book['added']) and book['good'] ):
self.add_book_or_update_format(book,options,prefs,mi) for first in (True,False):
if new_book: try:
## For failed chapters. Didn't have calibre_id before logger.debug("Attempting metadata update")
## add_book_or_update_format self.update_metadata(db, book['calibre_id'], book, mi, options)
self.update_error_column_loop(book,db,errorcol_label,lastcheckedcol_label) break
except:
if book['collision'] in (CALIBREONLY, CALIBREONLYSAVECOL) or \ det_msg = "".join(traceback.format_exception(*sys.exc_info())) # +"\n"+_("Story Details:")+pretty_book(book)
( (options['updatemeta'] or book['added']) and book['good'] ): logger.error("Error Updating Metadata:\n%s"%det_msg)
for first in (True,False): error_dialog(self.gui,
try: _("Error Updating Metadata"),
logger.debug("Attempting metadata update") "<p>"+_("An error has occurred while FanFicFare was updating calibre's metadata for <a href='%s'>%s</a>.")%(book['url'],book['title'])+"</p>"+
self.update_metadata(db, book['calibre_id'], book, mi, options) "<p>"+_("The ebook has been updated, but the metadata has not.")+"</p>"+
break ("<p><b>"+_("FanFicFare will try to update metadata again once. Close any interfering programs (such as Windows File Explorer) before closing this dialog.")+"</b></p>" if first else ""),
except: det_msg=det_msg,
det_msg = "".join(traceback.format_exception(*sys.exc_info())) # +"\n"+_("Story Details:")+pretty_book(book) show=True)
logger.error("Error Updating Metadata:\n%s"%det_msg) except Exception as e:
error_dialog(self.gui, logger.error("Exception: %s:%s"%(book,book['comment']),exc_info=True)
_("Error Updating Metadata"), det_msg = "".join(traceback.format_exception(*sys.exc_info())) # +"\n"+_("Story Details:")+pretty_book(book)
"<p>"+_("An error has occurred while FanFicFare was updating calibre's metadata for <a href='%s'>%s</a>.")%(book['url'],book['title'])+"</p>"+ error_dialog(self.gui,
"<p>"+_("The ebook has been updated, but the metadata has not.")+"</p>"+ _("Error Updating Metadata"),
("<p><b>"+_("FanFicFare will try to update metadata again once. Close any interfering programs (such as Windows File Explorer) before closing this dialog.")+"</b></p>" if first else ""), "<p>"+_("An error has occurred while FanFicFare was updating calibre's metadata for <a href='%s'>%s</a>.")%(book['url'],book['title'])+"</p>",
det_msg=det_msg, det_msg=det_msg,
show=True) show=True)
def update_books_finish(self, book_list, options={}, showlist=True): def update_books_finish(self, book_list, options={}, showlist=True):
'''Notify calibre about updated rows, update external plugins '''Notify calibre about updated rows, update external plugins