Commit 81f42637f0b31b768de0d90987a9e8395fd56d02

Authored by Alexis Koralewski
1 parent a444ac84
Exists in dev

F14 : When editing the obs config file, the website return yaml syntax errors

src/core/pyros_django/obsconfig/templates/obsconfig/edit_config.html
... ... @@ -26,6 +26,11 @@
26 26 left:80vw;
27 27 top: 30vh;
28 28 }
  29 + #message{
  30 + position:absolute;
  31 + left:80vw;
  32 + top: 25vh;
  33 + }
29 34  
30 35 .red{
31 36 color:red;
... ... @@ -46,8 +51,8 @@
46 51 <button class="btn-primary" id="check_config">Check schema</button>
47 52  
48 53 </div>
49   -<div id="save" class="hidden">
50 54 <p id="message"></p>
  55 +<div id="save" class="hidden">
51 56 {% comment %}
52 57 <label> File name: (without ".yml" extension)</label>
53 58  
... ... @@ -74,7 +79,6 @@
74 79 editor.resize();
75 80 });
76 81 document.getElementById("editor").addEventListener("input",function(){
77   - console.log("input")
78 82 $("#save").attr("class",'hidden')
79 83 $("#save_btn").removeAttr("disabled");
80 84 $("#save_message").empty();
... ... @@ -84,7 +88,6 @@
84 88 csrf_value = $("[name='csrfmiddlewaretoken']").val();
85 89 $.post('{% url 'verify_config' %}', { "config": editor.getValue(), csrfmiddlewaretoken: csrf_value }, function(data,status) {
86 90 console.log(data);
87   - console.log(status);
88 91 if(data["is_valid"] == true){
89 92 $("#message").empty().attr('class', 'normal').append("Valid configuration, do you want to save it ?");
90 93 $("#save").toggleClass('hidden');
... ... @@ -93,12 +96,20 @@
93 96 else{
94 97 $("#save").attr("class",'hidden')
95 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 243 temp_config_file.write(request.POST.get("config"))
244 244 temp_config_file.seek(0)
245 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 258 temp_config_file.seek(0)
248 259 schema = config_file["schema"]
249 260 errors = []
... ...