mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Make all Anki-native exceptions inherit from the same base class (#2028)
* Make all Anki-native exceptions inherit from same base class Allows add-ons to easily catch all Anki-native exceptions without being coupled to the currently implemented exceptions. * Satisfy pylint
This commit is contained in:
parent
79fbb6c8d8
commit
825c88b6e8
1 changed files with 21 additions and 6 deletions
|
@ -10,7 +10,22 @@ if TYPE_CHECKING:
|
||||||
import anki.collection
|
import anki.collection
|
||||||
|
|
||||||
|
|
||||||
class LocalizedError(Exception):
|
class AnkiException(Exception):
|
||||||
|
"""
|
||||||
|
General Anki exception that all custom exceptions raised by Anki should
|
||||||
|
inherit from. Allows add-ons to easily identify Anki-native exceptions.
|
||||||
|
|
||||||
|
When inheriting from a Python built-in exception other than `Exception`,
|
||||||
|
please supply `AnkiException` as an additional inheritance:
|
||||||
|
|
||||||
|
```
|
||||||
|
class MyNewAnkiException(ValueError, AnkiException):
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class LocalizedError(AnkiException):
|
||||||
"An error with a localized description."
|
"An error with a localized description."
|
||||||
|
|
||||||
def __init__(self, localized: str) -> None:
|
def __init__(self, localized: str) -> None:
|
||||||
|
@ -29,7 +44,7 @@ class DocumentedError(LocalizedError):
|
||||||
super().__init__(localized)
|
super().__init__(localized)
|
||||||
|
|
||||||
|
|
||||||
class Interrupted(Exception):
|
class Interrupted(AnkiException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +83,7 @@ class TemplateError(LocalizedError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NotFoundError(Exception):
|
class NotFoundError(AnkiException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,11 +91,11 @@ class DeletedError(LocalizedError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ExistsError(Exception):
|
class ExistsError(AnkiException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class UndoEmpty(Exception):
|
class UndoEmpty(AnkiException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,7 +111,7 @@ class SearchError(LocalizedError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AbortSchemaModification(Exception):
|
class AbortSchemaModification(AnkiException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue