mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Merge pull request #503 from Arthur-Milchior/error_msg_in_schema
Error msg in schema
This commit is contained in:
commit
2f02867840
1 changed files with 21 additions and 9 deletions
|
@ -601,11 +601,11 @@ and have been disabled: %(found)s"
|
||||||
# Schema
|
# Schema
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def _addonSchemaPath(self, dir):
|
def _addon_schema_path(self, dir):
|
||||||
return os.path.join(self.addonsFolder(dir), "config.schema.json")
|
return os.path.join(self.addonsFolder(dir), "config.schema.json")
|
||||||
|
|
||||||
def _addonSchema(self, dir):
|
def _addon_schema(self, dir):
|
||||||
path = self._addonSchemaPath(dir)
|
path = self._addon_schema_path(dir)
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
# True is a schema accepting everything
|
# True is a schema accepting everything
|
||||||
|
@ -1328,18 +1328,30 @@ class ConfigEditor(QDialog):
|
||||||
txt = gui_hooks.addon_config_editor_will_save_json(txt)
|
txt = gui_hooks.addon_config_editor_will_save_json(txt)
|
||||||
try:
|
try:
|
||||||
new_conf = json.loads(txt)
|
new_conf = json.loads(txt)
|
||||||
jsonschema.validate(new_conf, self.parent().mgr._addonSchema(self.addon))
|
jsonschema.validate(new_conf, self.parent().mgr._addon_schema(self.addon))
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
# The user did edit the configuration and entered a value
|
# The user did edit the configuration and entered a value
|
||||||
# which can not be interpreted.
|
# which can not be interpreted.
|
||||||
showInfo(
|
schema = e.schema
|
||||||
tr(
|
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,
|
TR.ADDONS_CONFIG_VALIDATION_ERROR,
|
||||||
problem=e.message,
|
problem=e.message,
|
||||||
path="/".join(str(path) for path in e.path),
|
path=path,
|
||||||
schema=str(e.schema),
|
schema=str(schema),
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
showInfo(msg)
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
showInfo(_("Invalid configuration: ") + repr(e))
|
showInfo(_("Invalid configuration: ") + repr(e))
|
||||||
|
|
Loading…
Reference in a new issue