Display all startup errors at once, and automatically disable add-ons

https://forums.ankiweb.net/t/anki-23-10-beta-5/35677/48
This commit is contained in:
Damien Elmes 2023-10-19 13:40:39 +10:00
parent 2d176d8c35
commit d7a0bc0d42
2 changed files with 26 additions and 12 deletions

View file

@ -4,6 +4,10 @@ addons-failed-to-load =
When loading '{ $name }': When loading '{ $name }':
{ $traceback } { $traceback }
addons-failed-to-load2 =
The following add-ons failed to load, so they have been disabled:
{ $addons }
# Shown in the add-on configuration screen (Tools>Add-ons>Config), in the title bar # Shown in the add-on configuration screen (Tools>Add-ons>Config), in the title bar
addons-config-window-title = Configure '{ $name }' addons-config-window-title = Configure '{ $name }'
addons-config-validation-error = There was a problem with the provided configuration: { $problem }, at path { $path }, against schema { $schema }. addons-config-validation-error = There was a problem with the provided configuration: { $problem }, at path { $path }, against schema { $schema }.

View file

@ -229,6 +229,7 @@ class AddonManager:
return os.path.join(root, module) return os.path.join(root, module)
def loadAddons(self) -> None: def loadAddons(self) -> None:
broken: list[str] = []
for addon in self.all_addon_meta(): for addon in self.all_addon_meta():
if not addon.enabled: if not addon.enabled:
continue continue
@ -240,13 +241,22 @@ class AddonManager:
except AbortAddonImport: except AbortAddonImport:
pass pass
except: except:
error = html.escape( self.toggleEnabled(addon.dir_name, enable=False)
tr.addons_failed_to_load( name = html.escape(addon.human_name())
name=addon.human_name(), page = addon.page()
traceback=traceback.format_exc(), if page:
broken.append(f"<a href={page}>{name}</a>")
else:
broken.append(name)
print(traceback.format_exc())
if broken:
addons = "\n\n- " + "\n- ".join(broken)
addons = f"<div style='white-space: pre-wrap'>{addons}</div>"
error = tr.addons_failed_to_load2(
addons=addons,
) )
) txt = f"<h1>{tr.qt_misc_error()}</h1>{error}"
txt = f"<h1>{tr.qt_misc_error()}</h1><div style='white-space: pre-wrap'>{error}</div>"
showText( showText(
txt, txt,
type="html", type="html",