Skip to content

Commit 81affe7

Browse files
Jonathan LudlamJonathan Ludlam
authored andcommitted
Improved backtracing of some of the exceptions thrown within the xml parsing
code. Signed-off-by: Rok Strnisa <[email protected]>
1 parent 3802cc3 commit 81affe7

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

ocaml/idl/ocaml_backend/genOCaml.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ let gen_to_xmlrpc api tys = block
101101
(** Generate code to marshal from the given datamodel type to XML-RPC. *)
102102
let ty_of_xmlrpc api ty =
103103
let alias_of_ty_param t = "("^(alias_of_ty t)^" param)" in
104-
let wrap var_binding b = "fun " ^ var_binding ^ " -> try ("^b^") with _ -> raise (Api_errors.Server_error (Api_errors.field_type_error,[param]))" in
104+
let wrap var_binding b = "fun " ^ var_binding ^ " -> try ("^b^") with _ -> log_backtrace (); raise (Api_errors.Server_error (Api_errors.field_type_error,[param]))" in
105105
let f = match ty with
106106
| Bool -> wrap "xml" "From.boolean xml"
107107
| DateTime -> wrap "xml" "From.datetime xml"
@@ -110,7 +110,7 @@ let ty_of_xmlrpc api ty =
110110
wrap "xml"
111111
("\n match String.lowercase (From.string xml) with\n "^
112112
String.concat "\n | " (List.map aux cs)^
113-
"\n | _ -> raise (RunTimeTypeError(\""^name^"\", xml))")
113+
"\n | _ -> log_backtrace(); raise (RunTimeTypeError(\""^name^"\", xml))")
114114
| Float -> wrap "xml" "From.double xml"
115115
| Int -> wrap "xml" "Int64.of_string(From.string xml)"
116116
| Map(key, value) ->
@@ -147,7 +147,7 @@ let ty_of_xmlrpc api ty =
147147
DT.Set (DT.Ref _) -> Some (DT.VSet [])
148148
| _ -> fld.DT.default_value in
149149
match default_value with
150-
None -> "(my_assoc \"" ^ field_name ^ "\" all)"
150+
None -> "(my_assoc \"" ^ field_name ^ "\" all)"
151151
| Some default ->
152152
Printf.sprintf "(if (List.mem_assoc \"%s\" all) then (my_assoc \"%s\" all) else %s)"
153153
field_name field_name

ocaml/idl/ocaml_backend/gen_api.ml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let gen_type highapi = function
3535
| ty -> [ "and "^OU.alias_of_ty ty^" = "^OU.ocaml_of_ty ty ]
3636

3737
let gen_client highapi =
38-
let all_types = DU.Types.of_objects (Dm_api.objects_of_api highapi) in
38+
let _ (* unused variable: all_types *) = DU.Types.of_objects (Dm_api.objects_of_api highapi) in
3939
List.iter (List.iter print)
4040
(List.between [""]
4141
[[ "open Xml";
@@ -49,20 +49,26 @@ let gen_client highapi =
4949
])
5050

5151
let gen_client_types highapi =
52-
let all_types = DU.Types.of_objects (Dm_api.objects_of_api highapi) in
53-
List.iter (List.iter print)
54-
(List.between [""]
55-
[[ "open Xml";
56-
"open XMLRPC";
57-
"open Date"; ];
58-
"type __unused = unit " :: (List.concat (List.map (gen_type highapi) all_types));
59-
GenOCaml.gen_of_xmlrpc highapi all_types;
60-
GenOCaml.gen_to_xmlrpc highapi all_types;
61-
O.Signature.strings_of (Gen_client.gen_signature highapi);
62-
])
52+
let all_types = DU.Types.of_objects (Dm_api.objects_of_api highapi) in
53+
List.iter (List.iter print)
54+
(List.between [""]
55+
[
56+
[
57+
"open Xml";
58+
"open XMLRPC";
59+
"open Date";
60+
"module D = Debug.Debugger(struct let name = \"backtrace\" end)";
61+
"open D"
62+
];
63+
"type __unused = unit " :: (List.concat (List.map (gen_type highapi) all_types));
64+
GenOCaml.gen_of_xmlrpc highapi all_types;
65+
GenOCaml.gen_to_xmlrpc highapi all_types;
66+
O.Signature.strings_of (Gen_client.gen_signature highapi);
67+
]
68+
)
6369

6470
let gen_server highapi =
65-
let all_types = DU.Types.of_objects (Dm_api.objects_of_api highapi) in
71+
let _ (* Unused variable: all_types *) = DU.Types.of_objects (Dm_api.objects_of_api highapi) in
6672
List.iter (List.iter print)
6773
(List.between [""]
6874
[[ "open Xml";

0 commit comments

Comments
 (0)