2019-02-05 04:59:03 +01:00
|
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
2012-12-21 08:51:59 +01:00
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2022-03-28 14:17:50 +02:00
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2017-12-11 07:20:00 +01:00
|
|
|
|
import html
|
2019-02-17 00:35:44 +01:00
|
|
|
|
import re
|
2019-12-20 10:19:03 +01:00
|
|
|
|
import sys
|
|
|
|
|
import traceback
|
2022-03-28 14:17:50 +02:00
|
|
|
|
from typing import TYPE_CHECKING, Optional, TextIO, cast
|
2013-10-22 08:30:46 +02:00
|
|
|
|
|
2020-02-23 09:01:34 +01:00
|
|
|
|
from markdown import markdown
|
|
|
|
|
|
2022-03-28 14:17:50 +02:00
|
|
|
|
import aqt
|
2022-10-21 10:02:12 +02:00
|
|
|
|
from anki.errors import BackendError, Interrupted
|
2013-10-22 08:30:46 +02:00
|
|
|
|
from aqt.qt import *
|
2021-03-26 05:21:04 +01:00
|
|
|
|
from aqt.utils import showText, showWarning, supportText, tr
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
2022-03-28 14:17:50 +02:00
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from aqt.main import AnkiQt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def show_exception(*, parent: QWidget, exception: Exception) -> None:
|
|
|
|
|
"Present a caught exception to the user using a pop-up."
|
Add apkg import/export on backend (#1743)
* Add apkg export on backend
* Filter out missing media-paths at write time
* Make TagMatcher::new() infallible
* Gather export data instead of copying directly
* Revert changes to rslib/src/tags/
* Reuse filename_is_safe/check_filename_safe()
* Accept func to produce MediaIter in export_apkg()
* Only store file folder once in MediaIter
* Use temporary tables for gathering
export_apkg() now accepts a search instead of a deck id. Decks are
gathered according to the matched notes' cards.
* Use schedule_as_new() to reset cards
* ExportData → ExchangeData
* Ignore ascii case when filtering system tags
* search_notes_cards_into_table →
search_cards_of_notes_into_table
* Start on apkg importing on backend
* Fix due dates in days for apkg export
* Refactor import-export/package
- Move media and meta code into appropriate modules.
- Normalize/check for normalization when deserializing media entries.
* Add SafeMediaEntry for deserialized MediaEntries
* Prepare media based on checksums
- Ensure all existing media files are hashed.
- Hash incoming files during preparation to detect conflicts.
- Uniquify names of conflicting files with hash (not notetype id).
- Mark media files as used while importing notes.
- Finally copy used media.
* Handle encoding in `replace_media_refs()`
* Add trait to keep down cow boilerplate
* Add notetypes immediately instaed of preparing
* Move target_col into Context
* Add notes immediately instaed of preparing
* Note id, not guid of conflicting notes
* Add import_decks()
* decks_configs → deck_configs
* Add import_deck_configs()
* Add import_cards(), import_revlog()
* Use dyn instead of generic for media_fn
Otherwise, would have to pass None with type annotation in the default
case.
* Fix signature of import_apkg()
* Fix search_cards_of_notes_into_table()
* Test new functions in text.rs
* Add roundtrip test for apkg (stub)
* Keep source id of imported cards (or skip)
* Keep source ids of imported revlog (or skip)
* Try to keep source ids of imported notes
* Make adding notetype with id undoable
* Wrap apkg import in transaction
* Keep source ids of imported deck configs (or skip)
* Handle card due dates and original due/did
* Fix importing cards/revlog
Card ids are manually uniquified.
* Factor out card importing
* Refactor card and revlog importing
* Factor out card importing
Also handle missing parents .
* Factor out note importing
* Factor out media importing
* Maybe upgrade scheduler of apkg
* Fix parent deck gathering
* Unconditionally import static media
* Fix deck importing edge cases
Test those edge cases, and add some global test helpers.
* Test note importing
* Let import_apkg() take a progress func
* Expand roundtrip apkg test
* Use fat pointer to avoid propogating generics
* Fix progress_fn type
* Expose apkg export/import on backend
* Return note log when importing apkg
* Fix archived collection name on apkg import
* Add CollectionOpWithBackendProgress
* Fix wrong Interrupted Exception being checked
* Add ClosedCollectionOp
* Add note ids to log and strip HTML
* Update progress when checking incoming media too
* Conditionally enable new importing in GUI
* Fix all_checksums() for media import
Entries of deleted files are nulled, not removed.
* Make apkg exporting on backend abortable
* Return number of notes imported from apkg
* Fix exception printing for QueryOp as well
* Add QueryOpWithBackendProgress
Also support backend exporting progress.
* Expose new apkg and colpkg exporting
* Open transaction in insert_data()
Was slowing down exporting by several orders of magnitude.
* Handle zstd-compressed apkg
* Add legacy arg to ExportAnkiPackage
Currently not exposed on the frontend
* Remove unused import in proto file
* Add symlink for typechecking of import_export_pb2
* Avoid kwargs in pb message creation, so typechecking is not lost
Protobuf's behaviour is rather subtle and I had to dig through the docs
to figure it out: set a field on a submessage to automatically assign
the submessage to the parent, or call SetInParent() to persist a default
version of the field you specified.
* Avoid re-exporting protobuf msgs we only use internally
* Stop after one test failure
mypy often fails much faster than pylint
* Avoid an extra allocation when extracting media checksums
* Update progress after prepare_media() finishes
Otherwise the bulk of the import ends up being shown as "Checked: 0"
in the progress window.
* Show progress of note imports
Note import is the slowest part, so showing progress here makes the UI
feel more responsive.
* Reset filtered decks at import time
Before this change, filtered decks exported with scheduling remained
filtered on import, and maybe_remove_from_filtered_deck() moved cards
into them as their home deck, leading to errors during review.
We may still want to provide a way to preserve filtered decks on import,
but to do that we'll need to ensure we don't rewrite the home decks of
cards, and we'll need to ensure the home decks are included as part of
the import (or give an error if they're not).
https://github.com/ankitects/anki/pull/1743/files#r839346423
* Fix a corner-case where due dates were shifted by a day
This issue existed in the old Python code as well. We need to include
the user's UTC offset in the exported file, or days_elapsed falls back
on the v1 cutoff calculation, which may be a day earlier or later than
the v2 calculation.
* Log conflicting note in remapped nt case
* take_fields() → into_fields()
* Alias `[u8; 20]` with `Sha1Hash`
* Truncate logged fields
* Rework apkg note import tests
- Use macros for more helpful errors.
- Split monolith into unit tests.
- Fix some unknown error with the previous test along the way.
(Was failing after 969484de4388d225c9f17d94534b3ba0094c3568.)
* Fix sorting of imported decks
Also adjust the test, so it fails without the patch. It was only passing
before, because the parent deck happened to come before the
inconsistently capitalised child alphabetically. But we want all parent
decks to be imported before their child decks, so their children can
adopt their capitalisation.
* target[_id]s → existing_card[_id]s
* export_collection_extracting_media() → ...
export_into_collection_file()
* target_already_exists→card_ordinal_already_exists
* Add search_cards_of_notes_into_table.sql
* Imrove type of apkg export selector/limit
* Remove redundant call to mod_schema()
* Parent tooltips to mw
* Fix a crash when truncating note text
String::truncate() is a bit of a footgun, and I've hit this before
too :-)
* Remove ExportLimit in favour of separate classes
* Remove OpWithBackendProgress and ClosedCollectionOp
Backend progress logic is now in ProgressManager. QueryOp can be used
for running on closed collection.
Also fix aborting of colpkg exports, which slipped through in #1817.
* Tidy up import log
* Avoid QDialog.exec()
* Default to excluding scheuling for deck list deck
* Use IncrementalProgress in whole import_export code
* Compare checksums when importing colpkgs
* Avoid registering changes if hashes are not needed
* ImportProgress::Collection → ImportProgress::File
* Make downgrading apkgs depend on meta version
* Generalise IncrementableProgress
And use it in entire import_export code instead.
* Fix type complexity lint
* Take count_map for IncrementableProgress::get_inner
* Replace import/export env with Shift click
* Accept all args from update() for backend progress
* Pass fields of ProgressUpdate explicitly
* Move update_interval into IncrementableProgress
* Outsource incrementing into Incrementor
* Mutate ProgressUpdate in progress_update callback
* Switch import/export legacy toggle to profile setting
Shift would have been nice, but the existing shortcuts complicate things.
If the user triggers an import with ctrl+shift+i, shift is unlikely to
have been released by the time our code runs, meaning the user accidentally
triggers the new code. We could potentially wait a while before bringing
up the dialog, but then we're forced to guess at how long it will take the
user to release the key.
One alternative would be to use alt instead of shift, but then we need to
trigger our shortcut when that key is pressed as well, and it could
potentially cause a conflict with an add-on that already uses that
combination.
* Show extension in export dialog
* Continue to provide separate options for schema 11+18 colpkg export
* Default to colpkg export when using File>Export
* Improve appearance of combo boxes when switching between apkg/colpkg
+ Deal with long deck names
* Convert newlines to spaces when showing fields from import
Ensures each imported note appears on a separate line
* Don't separate total note count from the other summary lines
This may come down to personal preference, but I feel the other counts
are equally as important, and separating them feels like it makes it
a bit easier to ignore them.
* Fix 'deck not normal' error when importing a filtered deck for the 2nd time
* Fix [Identical] being shown on first import
* Revert "Continue to provide separate options for schema 11+18 colpkg export"
This reverts commit 8f0b2c175f4794d642823b60414d142a12768441.
Will use a different approach
* Move legacy support into a separate exporter option; add to apkg export
* Adjust 'too new' message to also apply to .apkg import case
* Show a better message when attempting to import new apkg into old code
Previously the user could end seeing a message like:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 1: invalid start byte
Unfortunately we can't retroactively fix this for older clients.
* Hide legacy support option in older exporting screen
* Reflect change from paths to fnames in type & name
* Make imported decks normal at once
Then skip special casing in update_deck(). Also skip updating
description if new one is empty.
Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2022-05-02 13:12:46 +02:00
|
|
|
|
if isinstance(exception, Interrupted):
|
2022-03-28 14:17:50 +02:00
|
|
|
|
# nothing to do
|
|
|
|
|
return
|
2022-10-21 10:02:12 +02:00
|
|
|
|
if isinstance(exception, BackendError):
|
|
|
|
|
if exception.context:
|
|
|
|
|
print(exception.context)
|
|
|
|
|
if exception.backtrace:
|
|
|
|
|
print(exception.backtrace)
|
|
|
|
|
showWarning(str(exception), parent=parent, help=exception.help_page)
|
|
|
|
|
else:
|
2022-03-28 14:17:50 +02:00
|
|
|
|
# if the error is not originating from the backend, dump
|
|
|
|
|
# a traceback to the console to aid in debugging
|
|
|
|
|
traceback.print_exception(
|
|
|
|
|
None, exception, exception.__traceback__, file=sys.stdout
|
|
|
|
|
)
|
2022-10-21 10:02:12 +02:00
|
|
|
|
showWarning(str(exception), parent=parent)
|
2022-03-28 14:17:50 +02:00
|
|
|
|
|
|
|
|
|
|
2022-11-23 03:06:58 +01:00
|
|
|
|
def is_chromium_cert_error(error: str) -> bool:
|
|
|
|
|
"""QtWebEngine sometimes spits out 'unknown error' messages to stderr on Windows.
|
|
|
|
|
|
|
|
|
|
They appear to be IDS_SETTINGS_CERTIFICATE_MANAGER_UNKNOWN_ERROR in
|
|
|
|
|
chrome/browser/ui/webui/certificates_handler.cc. At a guess, it's the
|
|
|
|
|
NetErrorToString() method.
|
|
|
|
|
|
|
|
|
|
The constant appears to get converted to an ID; the resources are found
|
|
|
|
|
in files like this:
|
|
|
|
|
|
|
|
|
|
chrome/app/resources/generated_resources_fr-CA.xtb
|
|
|
|
|
2258:<translation id="3380365263193509176">Erreur inconnue</translation>
|
|
|
|
|
|
|
|
|
|
List derived with:
|
|
|
|
|
qtwebengine-chromium% rg --no-heading --no-filename --no-line-number \
|
|
|
|
|
3380365263193509176 | perl -pe 's/.*>(.*)<.*/"$1",/' | sort | uniq
|
|
|
|
|
|
|
|
|
|
Judging by error reports, we can't assume the error falls on a separate line:
|
|
|
|
|
https://forums.ankiweb.net/t/topic/22036/
|
|
|
|
|
"""
|
|
|
|
|
if not is_win:
|
|
|
|
|
return False
|
|
|
|
|
for msg in (
|
|
|
|
|
"알 수 없는 오류가 발생했습니다.",
|
|
|
|
|
"Bilinmeyen hata",
|
|
|
|
|
"Eroare necunoscută",
|
|
|
|
|
"Erreur inconnue",
|
|
|
|
|
"Erreur inconnue.",
|
|
|
|
|
"Erro descoñecido",
|
|
|
|
|
"Erro desconhecido",
|
|
|
|
|
"Error desconegut",
|
|
|
|
|
"Error desconocido",
|
|
|
|
|
"Errore ezezaguna",
|
|
|
|
|
"Errore sconosciuto",
|
|
|
|
|
"Gabim i panjohur",
|
|
|
|
|
"Hindi kilalang error",
|
|
|
|
|
"Hitilafu isiyojulikana",
|
|
|
|
|
"Iphutha elingaziwa",
|
|
|
|
|
"Ismeretlen hiba",
|
|
|
|
|
"Kesalahan tidak dikenal",
|
|
|
|
|
"Lỗi không xác định",
|
|
|
|
|
"Naməlum xəta",
|
|
|
|
|
"Nepoznata greška",
|
|
|
|
|
"Nepoznata pogreška",
|
|
|
|
|
"Nezināma kļūda",
|
|
|
|
|
"Nežinoma klaida",
|
|
|
|
|
"Neznáma chyba",
|
|
|
|
|
"Neznámá chyba",
|
|
|
|
|
"Neznana napaka",
|
|
|
|
|
"Nieznany błąd",
|
|
|
|
|
"Noma’lum xatolik",
|
|
|
|
|
"Okänt fel",
|
|
|
|
|
"Onbekende fout",
|
|
|
|
|
"Óþekkt villa",
|
|
|
|
|
"Ralat tidak diketahui",
|
|
|
|
|
"Tundmatu viga",
|
|
|
|
|
"Tuntematon virhe",
|
|
|
|
|
"Ukendt fejl",
|
|
|
|
|
"Ukjent feil",
|
|
|
|
|
"Unbekannter Fehler",
|
|
|
|
|
"Unknown error",
|
|
|
|
|
"Άγνωστο σφάλμα",
|
|
|
|
|
"Белгисиз ката",
|
|
|
|
|
"Белгісіз қате",
|
|
|
|
|
"Невідома помилка",
|
|
|
|
|
"Невядомая памылка",
|
|
|
|
|
"Неизвестна грешка",
|
|
|
|
|
"Неизвестная ошибка",
|
|
|
|
|
"Непозната грешка",
|
|
|
|
|
"Үл мэдэгдэх алдаа",
|
|
|
|
|
"უცნობი შეცდომა",
|
|
|
|
|
"Անհայտ սխալ",
|
|
|
|
|
"שגיאה לא ידועה",
|
|
|
|
|
"خطأ غير معروف",
|
|
|
|
|
"خطای ناشناس",
|
|
|
|
|
"نامعلوم خرابی",
|
|
|
|
|
"ያልታወቀ ስህተት",
|
|
|
|
|
"अज्ञात एरर",
|
|
|
|
|
"अज्ञात गड़बड़ी",
|
|
|
|
|
"अज्ञात त्रुटि",
|
|
|
|
|
"অজানা ত্রুটি",
|
|
|
|
|
"অজ্ঞাত আসোঁৱাহ",
|
|
|
|
|
"ਅਗਿਆਤ ਗੜਬੜ",
|
|
|
|
|
"અજ્ઞાત ભૂલ",
|
|
|
|
|
"ଅଜଣା ତୃଟି",
|
|
|
|
|
"அறியப்படாத பிழை",
|
|
|
|
|
"తెలియని ఎర్రర్",
|
|
|
|
|
"ಅಪರಿಚಿತ ದೋಷ",
|
|
|
|
|
"അജ്ഞാതമായ പിശക്",
|
|
|
|
|
"නොදන්නා දෝෂය",
|
|
|
|
|
"ข้อผิดพลาดที่ไม่รู้จัก",
|
|
|
|
|
"ຄວາມຜິດພາດທີ່ບໍ່ຮູ້ຈັກ",
|
|
|
|
|
"မသိရ အမှား",
|
|
|
|
|
"កំហុសឆ្គងមិនស្គាល់",
|
|
|
|
|
"不明なエラー",
|
|
|
|
|
"未知的錯誤",
|
|
|
|
|
"未知错误",
|
|
|
|
|
):
|
|
|
|
|
if error.startswith(msg):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
2017-01-08 11:30:34 +01:00
|
|
|
|
if not os.environ.get("DEBUG"):
|
2019-12-23 01:34:10 +01:00
|
|
|
|
|
2021-02-02 15:00:29 +01:00
|
|
|
|
def excepthook(etype, val, tb) -> None: # type: ignore
|
2019-12-23 01:34:10 +01:00
|
|
|
|
sys.stderr.write(
|
|
|
|
|
"Caught exception:\n%s\n"
|
|
|
|
|
% ("".join(traceback.format_exception(etype, val, tb)))
|
|
|
|
|
)
|
|
|
|
|
|
2017-01-08 11:30:34 +01:00
|
|
|
|
sys.excepthook = excepthook
|
2016-05-31 10:51:40 +02:00
|
|
|
|
|
2019-12-23 01:34:10 +01:00
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
|
class ErrorHandler(QObject):
|
|
|
|
|
"Catch stderr and write into buffer."
|
|
|
|
|
ivl = 100
|
2022-08-01 11:38:13 +02:00
|
|
|
|
fatal_error_encountered = False
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
2016-05-31 10:51:40 +02:00
|
|
|
|
errorTimer = pyqtSignal()
|
|
|
|
|
|
2021-02-01 13:08:56 +01:00
|
|
|
|
def __init__(self, mw: AnkiQt) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
|
QObject.__init__(self, mw)
|
|
|
|
|
self.mw = mw
|
2021-02-01 13:08:56 +01:00
|
|
|
|
self.timer: Optional[QTimer] = None
|
2020-05-04 05:23:08 +02:00
|
|
|
|
qconnect(self.errorTimer, self._setTimer)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
self.pool = ""
|
2017-06-26 05:03:05 +02:00
|
|
|
|
self._oldstderr = sys.stderr
|
2021-03-17 05:51:59 +01:00
|
|
|
|
sys.stderr = cast(TextIO, self)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
2021-02-01 13:08:56 +01:00
|
|
|
|
def unload(self) -> None:
|
2017-06-26 05:03:05 +02:00
|
|
|
|
sys.stderr = self._oldstderr
|
|
|
|
|
sys.excepthook = None
|
|
|
|
|
|
2021-02-01 13:08:56 +01:00
|
|
|
|
def write(self, data: str) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
|
# dump to stdout
|
2016-05-12 06:45:35 +02:00
|
|
|
|
sys.stdout.write(data)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
# save in buffer
|
|
|
|
|
self.pool += data
|
|
|
|
|
# and update timer
|
|
|
|
|
self.setTimer()
|
|
|
|
|
|
2021-02-01 13:08:56 +01:00
|
|
|
|
def setTimer(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
|
# we can't create a timer from a different thread, so we post a
|
|
|
|
|
# message to the object on the main thread
|
2020-07-24 19:19:40 +02:00
|
|
|
|
self.errorTimer.emit() # type: ignore
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
2021-02-01 13:08:56 +01:00
|
|
|
|
def _setTimer(self) -> None:
|
2012-12-21 08:51:59 +01:00
|
|
|
|
if not self.timer:
|
|
|
|
|
self.timer = QTimer(self.mw)
|
2020-05-04 05:23:08 +02:00
|
|
|
|
qconnect(self.timer.timeout, self.onTimeout)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
self.timer.setInterval(self.ivl)
|
|
|
|
|
self.timer.setSingleShot(True)
|
|
|
|
|
self.timer.start()
|
|
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
|
def tempFolderMsg(self) -> str:
|
2021-03-26 04:48:26 +01:00
|
|
|
|
return tr.qt_misc_unable_to_access_anki_media_folder()
|
2013-10-22 08:30:46 +02:00
|
|
|
|
|
2021-02-01 13:08:56 +01:00
|
|
|
|
def onTimeout(self) -> None:
|
2022-08-01 11:38:13 +02:00
|
|
|
|
if self.fatal_error_encountered:
|
|
|
|
|
# suppress follow-up errors caused by the poisoned lock
|
|
|
|
|
return
|
2017-12-11 07:20:00 +01:00
|
|
|
|
error = html.escape(self.pool)
|
2012-12-21 08:51:59 +01:00
|
|
|
|
self.pool = ""
|
|
|
|
|
self.mw.progress.clear()
|
2021-04-03 08:00:15 +02:00
|
|
|
|
if "AbortSchemaModification" in error:
|
2012-12-21 08:51:59 +01:00
|
|
|
|
return
|
2020-12-16 05:25:11 +01:00
|
|
|
|
if "DeprecationWarning" in error:
|
|
|
|
|
return
|
2017-07-09 05:26:50 +02:00
|
|
|
|
if "10013" in error:
|
2021-03-26 04:48:26 +01:00
|
|
|
|
showWarning(tr.qt_misc_your_firewall_or_antivirus_program_is())
|
2021-02-01 13:08:56 +01:00
|
|
|
|
return
|
2013-10-22 08:30:46 +02:00
|
|
|
|
if "invalidTempFolder" in error:
|
2021-02-01 13:08:56 +01:00
|
|
|
|
showWarning(self.tempFolderMsg())
|
|
|
|
|
return
|
2016-07-04 10:06:08 +02:00
|
|
|
|
if "Beautiful Soup is not an HTTP client" in error:
|
|
|
|
|
return
|
2019-04-23 02:19:05 +02:00
|
|
|
|
if "database or disk is full" in error or "Errno 28" in error:
|
2021-03-26 04:48:26 +01:00
|
|
|
|
showWarning(tr.qt_misc_your_computers_storage_may_be_full())
|
2021-02-01 13:08:56 +01:00
|
|
|
|
return
|
2014-07-22 01:01:19 +02:00
|
|
|
|
if "disk I/O error" in error:
|
2021-03-26 04:48:26 +01:00
|
|
|
|
showWarning(markdown(tr.errors_accessing_db()))
|
2020-02-23 09:01:34 +01:00
|
|
|
|
return
|
2022-11-23 03:06:58 +01:00
|
|
|
|
if is_chromium_cert_error(error):
|
|
|
|
|
return
|
2017-09-06 08:40:35 +02:00
|
|
|
|
|
2021-06-02 03:04:53 +02:00
|
|
|
|
if "PanicException" in error:
|
2022-08-01 11:38:13 +02:00
|
|
|
|
self.fatal_error_encountered = True
|
2021-06-02 03:04:53 +02:00
|
|
|
|
txt = markdown(
|
|
|
|
|
"**A fatal error occurred, and Anki must close. Please report this message on the forums.**"
|
|
|
|
|
)
|
|
|
|
|
error = f"{supportText() + self._addonText(error)}\n{error}"
|
|
|
|
|
elif self.mw.addonManager.dirty:
|
2022-03-28 10:54:18 +02:00
|
|
|
|
# Older translations include a link to the old discussions site; rewrite it to a newer one
|
|
|
|
|
message = tr.errors_addons_active_popup().replace(
|
|
|
|
|
"https://help.ankiweb.net/discussions/add-ons/",
|
|
|
|
|
"https://forums.ankiweb.net/c/add-ons/11",
|
|
|
|
|
)
|
|
|
|
|
txt = markdown(message)
|
2021-02-11 01:09:06 +01:00
|
|
|
|
error = f"{supportText() + self._addonText(error)}\n{error}"
|
2012-12-21 08:51:59 +01:00
|
|
|
|
else:
|
2021-03-26 04:48:26 +01:00
|
|
|
|
txt = markdown(tr.errors_standard_popup())
|
2021-02-11 01:09:06 +01:00
|
|
|
|
error = f"{supportText()}\n{error}"
|
2019-12-23 01:34:10 +01:00
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
|
# show dialog
|
2021-02-11 01:09:06 +01:00
|
|
|
|
txt = f"{txt}<div style='white-space: pre-wrap'>{error}</div>"
|
2019-02-16 23:05:06 +01:00
|
|
|
|
showText(txt, type="html", copyBtn=True)
|
2022-08-01 11:38:13 +02:00
|
|
|
|
if self.fatal_error_encountered:
|
2021-06-02 03:04:53 +02:00
|
|
|
|
sys.exit(1)
|
2017-09-06 08:40:35 +02:00
|
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
|
def _addonText(self, error: str) -> str:
|
2023-06-07 07:09:18 +02:00
|
|
|
|
matches = re.findall(r"addons21(/|\\)(.*?)(/|\\)", error)
|
2019-02-17 00:35:44 +01:00
|
|
|
|
if not matches:
|
|
|
|
|
return ""
|
|
|
|
|
# reverse to list most likely suspect first, dict to deduplicate:
|
2019-12-23 01:34:10 +01:00
|
|
|
|
addons = [
|
2023-06-07 07:09:18 +02:00
|
|
|
|
aqt.mw.addonManager.addonName(i[1])
|
|
|
|
|
for i in dict.fromkeys(reversed(matches))
|
2019-12-23 01:34:10 +01:00
|
|
|
|
]
|
2019-02-17 00:35:44 +01:00
|
|
|
|
# highlight importance of first add-on:
|
2021-02-11 01:09:06 +01:00
|
|
|
|
addons[0] = f"<b>{addons[0]}</b>"
|
2020-02-27 11:32:57 +01:00
|
|
|
|
addons_str = ", ".join(addons)
|
2021-03-26 05:21:04 +01:00
|
|
|
|
return f"{tr.addons_possibly_involved(addons=addons_str)}\n"
|