Commit 81f42637f0b31b768de0d90987a9e8395fd56d02
1 parent
a444ac84
Exists in
dev
F14 : When editing the obs config file, the website return yaml syntax errors
Showing
2 changed files
with
30 additions
and
8 deletions
Show diff stats
src/core/pyros_django/obsconfig/templates/obsconfig/edit_config.html
@@ -26,6 +26,11 @@ | @@ -26,6 +26,11 @@ | ||
26 | left:80vw; | 26 | left:80vw; |
27 | top: 30vh; | 27 | top: 30vh; |
28 | } | 28 | } |
29 | + #message{ | ||
30 | + position:absolute; | ||
31 | + left:80vw; | ||
32 | + top: 25vh; | ||
33 | + } | ||
29 | 34 | ||
30 | .red{ | 35 | .red{ |
31 | color:red; | 36 | color:red; |
@@ -46,8 +51,8 @@ | @@ -46,8 +51,8 @@ | ||
46 | <button class="btn-primary" id="check_config">Check schema</button> | 51 | <button class="btn-primary" id="check_config">Check schema</button> |
47 | 52 | ||
48 | </div> | 53 | </div> |
49 | -<div id="save" class="hidden"> | ||
50 | <p id="message"></p> | 54 | <p id="message"></p> |
55 | +<div id="save" class="hidden"> | ||
51 | {% comment %} | 56 | {% comment %} |
52 | <label> File name: (without ".yml" extension)</label> | 57 | <label> File name: (without ".yml" extension)</label> |
53 | 58 | ||
@@ -74,7 +79,6 @@ | @@ -74,7 +79,6 @@ | ||
74 | editor.resize(); | 79 | editor.resize(); |
75 | }); | 80 | }); |
76 | document.getElementById("editor").addEventListener("input",function(){ | 81 | document.getElementById("editor").addEventListener("input",function(){ |
77 | - console.log("input") | ||
78 | $("#save").attr("class",'hidden') | 82 | $("#save").attr("class",'hidden') |
79 | $("#save_btn").removeAttr("disabled"); | 83 | $("#save_btn").removeAttr("disabled"); |
80 | $("#save_message").empty(); | 84 | $("#save_message").empty(); |
@@ -84,7 +88,6 @@ | @@ -84,7 +88,6 @@ | ||
84 | csrf_value = $("[name='csrfmiddlewaretoken']").val(); | 88 | csrf_value = $("[name='csrfmiddlewaretoken']").val(); |
85 | $.post('{% url 'verify_config' %}', { "config": editor.getValue(), csrfmiddlewaretoken: csrf_value }, function(data,status) { | 89 | $.post('{% url 'verify_config' %}', { "config": editor.getValue(), csrfmiddlewaretoken: csrf_value }, function(data,status) { |
86 | console.log(data); | 90 | console.log(data); |
87 | - console.log(status); | ||
88 | if(data["is_valid"] == true){ | 91 | if(data["is_valid"] == true){ |
89 | $("#message").empty().attr('class', 'normal').append("Valid configuration, do you want to save it ?"); | 92 | $("#message").empty().attr('class', 'normal').append("Valid configuration, do you want to save it ?"); |
90 | $("#save").toggleClass('hidden'); | 93 | $("#save").toggleClass('hidden'); |
@@ -93,12 +96,20 @@ | @@ -93,12 +96,20 @@ | ||
93 | else{ | 96 | else{ |
94 | $("#save").attr("class",'hidden') | 97 | $("#save").attr("class",'hidden') |
95 | $("#message").empty().attr('class', 'red').append("Invalid configruation, see the errors below:"); | 98 | $("#message").empty().attr('class', 'red').append("Invalid configruation, see the errors below:"); |
96 | - for(error of data["message"] ){ | ||
97 | - for(message of error){ | ||
98 | - $("#message").append("<p>"+message+"</p>"); | 99 | + if (data["message"]){ |
100 | + for(error of data["message"] ){ | ||
101 | + for(message of error){ | ||
102 | + $("#message").append("<p>"+message+"</p>"); | ||
99 | 103 | ||
100 | - } | 104 | + } |
101 | 105 | ||
106 | + } | ||
107 | + } | ||
108 | + console.log(data["yaml_error_message"]) | ||
109 | + if (data["yaml_error_message"]){ | ||
110 | + console.log("yaml_error_message") | ||
111 | + let message = data["yaml_error_message"]; | ||
112 | + $("#message").append("<p><pre>"+message+"</pre></p>"); | ||
102 | } | 113 | } |
103 | } | 114 | } |
104 | }); | 115 | }); |
src/core/pyros_django/obsconfig/views.py
@@ -243,7 +243,18 @@ def verify_config(request): | @@ -243,7 +243,18 @@ def verify_config(request): | ||
243 | temp_config_file.write(request.POST.get("config")) | 243 | temp_config_file.write(request.POST.get("config")) |
244 | temp_config_file.seek(0) | 244 | temp_config_file.seek(0) |
245 | response_data = {} | 245 | response_data = {} |
246 | - config_file = yaml.safe_load(temp_config_file.read()) | 246 | + try: |
247 | + config_file = yaml.safe_load(temp_config_file.read()) | ||
248 | + except yaml.YAMLError as exc: | ||
249 | + if hasattr(exc, 'problem_mark'): | ||
250 | + yaml_error_message = "" | ||
251 | + if exc.context != None: | ||
252 | + yaml_error_message += str(exc.problem_mark) + '\n ' + str(exc.problem) + ' ' + str(exc.context) | ||
253 | + else: | ||
254 | + yaml_error_message = str(exc.problem_mark.name) + '\n ' +str(exc.problem) | ||
255 | + response_data["is_valid"] = False | ||
256 | + response_data["yaml_error_message"] = yaml_error_message | ||
257 | + return HttpResponse(json.dumps(response_data), content_type="application/json") | ||
247 | temp_config_file.seek(0) | 258 | temp_config_file.seek(0) |
248 | schema = config_file["schema"] | 259 | schema = config_file["schema"] |
249 | errors = [] | 260 | errors = [] |