mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-25 14:35:51 +08:00
[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:
committed by
GitHub
parent
7dff606068
commit
5dfb6f2259
@@ -68,20 +68,24 @@ let send_aircrafts_msg = fun _asker _values ->
|
||||
|
||||
let expand_aicraft x =
|
||||
let ac_name = ExtXml.attrib x "name" in
|
||||
let handle_error_message = fun error_type msg ->
|
||||
prerr_endline ("A failure occurred while processing aircraft '"^ac_name^"'");
|
||||
prerr_endline (" - "^error_type^" : "^msg);
|
||||
prerr_endline (" - '"^ac_name^"' will be ignored by the server");
|
||||
prerr_endline " - Please remove it from 'conf.xml' or fix its parameter(s)";
|
||||
flush stderr;
|
||||
Xml.Element ("ignoring_aircraft",["name", ac_name],[])
|
||||
in
|
||||
try
|
||||
let ac = Aircraft.parse_aircraft ~parse_all:true "" x in
|
||||
if List.length ac.Aircraft.xml > 0 then Xml.Element (Xml.tag x, Xml.attribs x, ac.Aircraft.xml)
|
||||
else failwith "Nothing to parse"
|
||||
with Failure msg ->
|
||||
begin
|
||||
prerr_endline ("A failure occurred while processing aircraft '"^ac_name^"'");
|
||||
prerr_endline (" - Fail with : "^msg);
|
||||
prerr_endline (" - '"^ac_name^"' will be ignored by the server");
|
||||
prerr_endline " - Please remove it from 'conf.xml' or fix its parameter(s)";
|
||||
flush stderr;
|
||||
(*failwith msg*)
|
||||
Xml.Element ("ignoring_aircraft",["name", ac_name],[])
|
||||
end
|
||||
with
|
||||
| Failure msg -> handle_error_message "Fail with" msg
|
||||
| Xml.File_not_found file -> handle_error_message "File not found" file
|
||||
| Module.Module_not_found m -> handle_error_message "Module not found" m
|
||||
| Dtd.Prove_error err -> handle_error_message "Dtd error" (Dtd.prove_error err)
|
||||
| Not_found -> handle_error_message "Not found" "sorry, something went wrong somewhere"
|
||||
|
||||
let make_element = fun t a c -> Xml.Element (t,a,c)
|
||||
|
||||
@@ -901,7 +905,6 @@ let () =
|
||||
"Usage: ";
|
||||
|
||||
Srtm.add_path srtm_path;
|
||||
|
||||
Ivy.init "Paparazzi server" "READY" (fun _ _ -> ());
|
||||
Ivy.start !ivy_bus;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user