[fix] handle more exceptions when parsing conf (#2562)

it is currently crashing the server when their is an error in the conf
files
This commit is contained in:
Gautier Hattenberger
2020-08-17 18:21:39 +02:00
committed by GitHub
parent 7dff606068
commit 5dfb6f2259
2 changed files with 31 additions and 18 deletions
+17 -7
View File
@@ -109,7 +109,7 @@ let rec target_conf_add_module = fun conf target firmware name mtype load_type -
(* sort element of an airframe type by target *)
let sort_airframe_by_target = fun config_by_target airframe ->
match airframe with
| None -> ()
| None -> []
| Some a ->
(* build a list of pairs (target, firmware) *)
let l = List.fold_left (fun lf f ->
@@ -150,7 +150,9 @@ let sort_airframe_by_target = fun config_by_target airframe ->
) c m.Airframe.OldModules.modules
) conf a.Airframe.modules in
Hashtbl.add config_by_target name conf
) l
) l;
(* return list of targets *)
fst (List.split l)
(** Extract a configuration element from aircraft config,
* returns a tuple with absolute file path and element object
@@ -201,7 +203,7 @@ let get_all_modules = fun config_by_target ->
let parse_aircraft = fun ?(parse_af=false) ?(parse_ap=false) ?(parse_fp=false) ?(parse_rc=false) ?(parse_tl=false) ?(parse_set=false) ?(parse_all=false) ?(verbose=false) target aircraft_xml ->
let name = Xml.attrib aircraft_xml "name" in
let name = ExtXml.attrib aircraft_xml "name" in
let conf_aircraft = [] in (* accumulate aircraft XML config *)
let config_by_target = Hashtbl.create 5 in
@@ -214,7 +216,7 @@ let parse_aircraft = fun ?(parse_af=false) ?(parse_ap=false) ?(parse_fp=false) ?
let conf_aircraft = conf_aircraft @ (match airframe with None -> [] | Some x -> [x.Airframe.xml]) in
if verbose then
Printf.printf ", sorting by target%!";
sort_airframe_by_target config_by_target airframe;
let target_list = sort_airframe_by_target config_by_target airframe in
if verbose then
Printf.printf ", extracting and parsing autopilot...%!";
let autopilots = if parse_ap || parse_all then
@@ -253,9 +255,17 @@ let parse_aircraft = fun ?(parse_af=false) ?(parse_ap=false) ?(parse_fp=false) ?
) config_by_target;
(af_ap.Airframe.Autopilot.freq, ap)
) autopilots in
let c = Hashtbl.find config_by_target target in
Hashtbl.replace config_by_target target { c with autopilot = true };
Some autopilots
try
let c = Hashtbl.find config_by_target target in
Hashtbl.replace config_by_target target { c with autopilot = true };
Some autopilots
with Not_found ->
(* target not found or not defined, add in all targets instead *)
List.iter (fun t ->
let c = Hashtbl.find config_by_target target in
Hashtbl.replace config_by_target target { c with autopilot = true }
) target_list;
Some autopilots
end
else None in
let conf_aircraft = conf_aircraft @ (match autopilots with None -> [] | Some lx -> List.map (fun (_, x) -> x.Autopilot.xml) lx) in