From ef925a88d6325bdddf91d4bad33f68ff9cb3e78d Mon Sep 17 00:00:00 2001 From: RumovZ Date: Fri, 26 Feb 2021 11:32:26 +0100 Subject: [PATCH] Add filtered deck error localisation on backend --- ftl/core/errors.ftl | 3 +-- pylib/anki/errors.py | 21 ++++++++++----------- rslib/src/err.rs | 1 + 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ftl/core/errors.ftl b/ftl/core/errors.ftl index 8e549ecb1..23a8cc7a3 100644 --- a/ftl/core/errors.ftl +++ b/ftl/core/errors.ftl @@ -1,5 +1,4 @@ -errors-invalid-deck-name = Invalid deck name: { $reason } errors-invalid-input-empty = Invalid input. errors-invalid-input-details = Invalid input: { $details } errors-parse-number-fail = A number was invalid or out of range. -errors-reason-filtered-parent = Filtered decks cannot be parent decks. +errors-filtered-parent-deck = Invalid deck name: Filtered decks cannot be parent decks. diff --git a/pylib/anki/errors.py b/pylib/anki/errors.py index 0fd0a5abb..7ca87996d 100644 --- a/pylib/anki/errors.py +++ b/pylib/anki/errors.py @@ -47,7 +47,15 @@ class ExistsError(Exception): pass -class DeckIsFilteredError(Exception): +class DeckRenameError(Exception): + """Legacy error, use DeckIsFilteredError instead.""" + + def __init__(self, description: str, *args: object) -> None: + super().__init__(description, *args) + self.description = description + + +class DeckIsFilteredError(StringError, DeckRenameError): pass @@ -78,7 +86,7 @@ def backend_exception_to_pylib(err: _pb.BackendError) -> Exception: elif val == "exists": return ExistsError() elif val == "deck_is_filtered": - return DeckIsFilteredError() + return DeckIsFilteredError(err.localized) elif val == "proto_error": return StringError(err.localized) else: @@ -95,12 +103,3 @@ class AnkiError(Exception): def __str__(self) -> str: return self.type - - -class DeckRenameError(Exception): - def __init__(self, description: str) -> None: - super().__init__() - self.description = description - - def __str__(self) -> str: - return f"Couldn't rename deck: {self.description}" diff --git a/rslib/src/err.rs b/rslib/src/err.rs index 6a93df75b..77f714599 100644 --- a/rslib/src/err.rs +++ b/rslib/src/err.rs @@ -208,6 +208,7 @@ impl AnkiError { } } AnkiError::ParseNumError => i18n.tr(TR::ErrorsParseNumberFail).into(), + AnkiError::DeckIsFiltered => i18n.tr(TR::ErrorsFilteredParentDeck).into(), _ => format!("{:?}", self), } }