From 4d952ce0070dbbe968429a11ead289f2cfa082d4 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Fri, 10 Jun 2022 15:18:36 +0800 Subject: [PATCH] config_tools: conduct full validation on save This patch makes the configurator validate both syntactically and semantically the resulting scenario XML everytime users save their configurations. This allows the validation to catch all errors and report status properly. While a full validation is conducted, the syntactic errors are not shown at the top of the forms in the same way as the semantic ones. This is because syntactic rules are already built into the JSON schema and will be warned real-time under the corresponding widgets. There is no need to duplicate such errors. At the same time, the messages of syntactic errors are generated by xmlschema which may not look friendly to end users who do not have knowledge about the internal structures of scenario XMLs. Tracked-On: #6691 Signed-off-by: Junjie Mao --- .../packages/configurator/src/pages/Config.vue | 8 +++++--- .../configurator/pyodide/validateScenario.py | 9 ++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue index 9e4f794d7..c1ebddee9 100644 --- a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue +++ b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue @@ -183,7 +183,8 @@ export default { }, scenarioUpdate(scenarioData) { let scenarioXMLData = this.scenarioToXML(scenarioData) - this.errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData) + let all_errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData) + this.errors = all_errors.semantic_errors this.scenario = scenarioData; this.showFlag = false; this.updateCurrentFormSchema() @@ -428,9 +429,10 @@ export default { .then(() => { stepDone = 1 console.log("validate settings...") - this.errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData) + let all_errors = configurator.pythonObject.validateScenario(this.board.content, scenarioXMLData) + this.errors = all_errors.semantic_errors // noinspection ExceptionCaughtLocallyJS - if (this.errors.length !== 0) { + if (all_errors.syntactic_errors.length !== 0 || all_errors.semantic_errors.length !== 0) { throw new Error("validation failed") } console.log("validation ok") diff --git a/misc/config_tools/configurator/pyodide/validateScenario.py b/misc/config_tools/configurator/pyodide/validateScenario.py index 0509cf04b..06bdd6773 100644 --- a/misc/config_tools/configurator/pyodide/validateScenario.py +++ b/misc/config_tools/configurator/pyodide/validateScenario.py @@ -27,11 +27,9 @@ def main(board, scenario): XMLLoadStage("board"), XMLLoadStage("scenario"), DefaultValuePopulatingStage(), + SyntacticValidationStage(), SemanticValidationStage(), ] - # - # if is_debug: - # stages.append(SyntacticValidationStage()) pipeline.add_stages(stages) with TemporaryDirectory() as tmpdir: @@ -50,8 +48,9 @@ def main(board, scenario): ) pipeline.run(obj) - validate_result = obj.get("semantic_errors") - return convert_result(validate_result) + syntactic_errors = obj.get("syntactic_errors") + semantic_errors = obj.get("semantic_errors") + return convert_result({"syntactic_errors": syntactic_errors, "semantic_errors": semantic_errors}) def test():