mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Allow add-on dev to show personalized message.
The error should be in "error_msg" They can show: * the original error message with {problem} * the path of the error with {path}, * the value which does not match against the subchema with {error} * the subschema against which the error occurs with {schema} Thanks to Glutanimate for the idea https://github.com/ankitects/anki/pull/495#issuecomment-596685227
This commit is contained in:
parent
0b04da6419
commit
5482cafef2
1 changed files with 17 additions and 5 deletions
|
@ -1332,14 +1332,26 @@ class ConfigEditor(QDialog):
|
|||
except ValidationError as e:
|
||||
# The user did edit the configuration and entered a value
|
||||
# which can not be interpreted.
|
||||
showInfo(
|
||||
tr(
|
||||
schema = e.schema
|
||||
erroneous_conf = new_conf
|
||||
for link in e.path:
|
||||
erroneous_conf = erroneous_conf[link]
|
||||
path = "/".join(str(path) for path in e.path)
|
||||
if "error_msg" in schema:
|
||||
msg = schema["error_msg"].format(
|
||||
problem=e.message,
|
||||
path=path,
|
||||
schema=str(schema),
|
||||
erroneous_conf=erroneous_conf,
|
||||
)
|
||||
else:
|
||||
msg = tr(
|
||||
TR.ADDONS_CONFIG_VALIDATION_ERROR,
|
||||
problem=e.message,
|
||||
path="/".join(str(path) for path in e.path),
|
||||
schema=str(e.schema),
|
||||
path=path,
|
||||
schema=str(schema),
|
||||
)
|
||||
)
|
||||
showInfo(msg)
|
||||
return
|
||||
except Exception as e:
|
||||
showInfo(_("Invalid configuration: ") + repr(e))
|
||||
|
|
Loading…
Reference in a new issue