Skip to content

Commit 78c855c

Browse files
Julowsmorimoto
authored andcommitted
Eliom_lib: Unify raise_error and raise_error_f
This makes logging error more regular accross client code and remove one function from the toplevel namespace. raise_error is almost always used with a string literal argument, making it interchangeable with raise_error_f in practice.
1 parent c623ff7 commit 78c855c

File tree

7 files changed

+25
-35
lines changed

7 files changed

+25
-35
lines changed

src/lib/client/eliommod_dom.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ let slow_select_nodes (root : Dom_html.element Js.t) =
248248
| Dom_html.A e -> ignore a_array ## (push e)
249249
| Dom_html.Form e -> ignore form_array ## (push e)
250250
| _ ->
251-
raise_error_f ~section "%s element tagged as eliom link"
251+
raise_error ~section "%s element tagged as eliom link"
252252
(Js.to_string node##.tagName));
253253
if process_node then ignore node_array ## (push node);
254254
if closure then ignore closure_array ## (push node);
@@ -349,8 +349,7 @@ let add_childrens (elt : Dom_html.element Js.t) (sons : Dom.node Js.t list) =
349349
match Dom.nodeType t with
350350
| Dom.Text t -> t
351351
| _ ->
352-
raise_error_f ~section
353-
"add_childrens: not text node in tag %s"
352+
raise_error ~section "add_childrens: not text node in tag %s"
354353
(Js.to_string elt##.tagName)
355354
in
356355
concat acc ## (concat txt##.data) q

src/lib/eliom_client.client.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ let a_handler =
179179
Dom_html.full_handler (fun node ev ->
180180
let node =
181181
Js.Opt.get (Dom_html.CoerceTo.a node) (fun () ->
182-
raise_error_f ~section "not an anchor element")
182+
raise_error ~section "not an anchor element")
183183
in
184184
(* We prevent default behaviour
185185
only if raw_a_handler has taken the change page itself *)
@@ -196,7 +196,7 @@ let form_handler :
196196
Dom_html.full_handler (fun node ev ->
197197
let form =
198198
Js.Opt.get (Dom_html.CoerceTo.form node) (fun () ->
199-
raise_error_f ~section "not a form element")
199+
raise_error ~section "not a form element")
200200
in
201201
let kind =
202202
if String.lowercase_ascii (Js.to_string form##._method) = "get"
@@ -213,7 +213,7 @@ let relink_process_node (node : Dom_html.element Js.t) =
213213
let id =
214214
Js.Opt.get
215215
node ## (getAttribute (Js.string Eliom_runtime.RawXML.node_id_attrib))
216-
(fun () -> raise_error_f ~section "unique node without id attribute")
216+
(fun () -> raise_error ~section "unique node without id attribute")
217217
in
218218
Js.Optdef.case
219219
(Eliom_client_core.find_process_node id)
@@ -240,7 +240,7 @@ let relink_request_node (node : Dom_html.element Js.t) =
240240
let id =
241241
Js.Opt.get
242242
node ## (getAttribute (Js.string Eliom_runtime.RawXML.node_id_attrib))
243-
(fun () -> raise_error_f ~section "unique node without id attribute")
243+
(fun () -> raise_error ~section "unique node without id attribute")
244244
in
245245
Js.Optdef.case
246246
(Eliom_client_core.find_request_node id)
@@ -373,7 +373,7 @@ let relink_attrib _root table (node : Dom_html.element Js.t) =
373373
in
374374
Eliom_client_core.rebuild_rattrib node rattrib
375375
with Not_found ->
376-
raise_error_f ~section "relink_attrib: client value %s not found" cid
376+
raise_error ~section "relink_attrib: client value %s not found" cid
377377
in
378378
Eliommod_dom.iter_attrList node##.attributes aux
379379

@@ -398,10 +398,10 @@ let load_data_script page =
398398
match Js.to_bytestring data_script##.tagName##toLowerCase with
399399
| "script" -> Js.Unsafe.coerce data_script
400400
| t ->
401-
raise_error_f ~section
401+
raise_error ~section
402402
"Unable to find Eliom application data (script element expected, found %s element)"
403403
t)
404-
| _ -> raise_error_f ~section "Unable to find Eliom application data."
404+
| _ -> raise_error ~section "Unable to find Eliom application data."
405405
in
406406
let script = data_script##.text in
407407
if !Eliom_config.debug_timings
@@ -822,7 +822,7 @@ let get_state state_id : state =
822822
(* We use this only when the history API is
823823
available. Sessionstorage seems to be available
824824
everywhere the history API exists. *)
825-
raise_error_f ~section "sessionStorage not available")
825+
raise_error ~section "sessionStorage not available")
826826
(fun s -> s ## (getItem (state_key state_id))))
827827
(fun () -> raise Not_found)
828828
(fun s -> of_json ~typ:[%json: state] (Js.to_string s))

src/lib/eliom_client_core.client.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ end = struct
8787
| None -> ""
8888
| Some p -> Printf.sprintf "(%s)" (Eliom_lib.pos_to_string p)
8989
in
90-
raise_error_f ~section
90+
raise_error ~section
9191
"Client closure %s not found %s (is the module linked on the client?)"
9292
closure_id pos
9393
in
@@ -136,7 +136,7 @@ end = struct
136136
Printf.sprintf "%s (%s at %s)" name i
137137
(Eliom_lib.pos_to_string pos)
138138
in
139-
raise_error_f "Did not find injection %s" name))
139+
raise_error "Did not find injection %s" name))
140140

141141
let initialize ~compilation_unit_id
142142
{Eliom_runtime.injection_id; injection_value; _}
@@ -168,7 +168,7 @@ let do_next_server_section_data ~compilation_unit_id =
168168
data.server_section <- r;
169169
Array.iter Client_value.initialize l
170170
| [] ->
171-
raise_error_f ~section
171+
raise_error ~section
172172
"Queue of client value data for compilation unit %s is empty (is it linked on the server?)"
173173
compilation_unit_id
174174
with Not_found -> ()
@@ -184,7 +184,7 @@ let do_next_client_section_data ~compilation_unit_id =
184184
data.client_section <- r;
185185
Array.iter (fun i -> Injection.initialize ~compilation_unit_id i) l
186186
| [] ->
187-
raise_error_f ~section
187+
raise_error ~section
188188
"Queue of injection data for compilation unit %s is empty (is it linked on the server?)"
189189
compilation_unit_id
190190
with Not_found -> ()
@@ -732,7 +732,7 @@ let rebuild_node_ns ns context elt' =
732732
elt' context;
733733
if is_before_initial_load ()
734734
then
735-
raise_error_f ~section ~inspect:(rebuild_node' ns elt')
735+
raise_error ~section ~inspect:(rebuild_node' ns elt')
736736
"Cannot apply %s%s before the document is initially loaded" context
737737
Xml.(
738738
match get_node_id elt' with

src/lib/eliom_comet.client.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ let handle_exn, set_handle_exn_function =
185185
"Unknown exception during comet. Customize this with Eliom_comet.set_handle_exn_function. "
186186
in
187187
match exn with
188-
| Some exn -> raise_error ~section ~exn s
188+
| Some exn -> raise_error ~section ~exn "%s" s
189189
| None -> Lwt_log.debug ~section s)
190190
in
191191
( (fun ?exn () ->

src/lib/eliom_content_.client.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct
5454
let elt' = Kind.toelt elt in
5555
match Xml.get_node_id elt' with
5656
| Xml.NoId ->
57-
raise_error_f ~section:eliom_logs_src
57+
raise_error ~section:eliom_logs_src
5858
~inspect:
5959
(Eliom_client_core.rebuild_node' Ns.content_ns (Kind.toelt elt))
6060
"Cannot call %s on an element with functional semantics" context
@@ -64,7 +64,7 @@ struct
6464
Js.Opt.case
6565
(Dom_html.CoerceTo.element (get_unique_node name elt))
6666
(fun () ->
67-
raise_error_f ~section:eliom_logs_src
67+
raise_error ~section:eliom_logs_src
6868
~inspect:
6969
(Eliom_client_core.rebuild_node' Ns.content_ns (Kind.toelt elt))
7070
"Cannot call %s on a node which is not an element" name)

src/lib/eliom_lib.client.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ end
8181

8282
module Lwt_log = Lwt_log_js
8383

84-
let raise_error ?inspect ?exn ?section ?location ?logger msg =
85-
Lwt.ignore_result
86-
(Lwt_log.log ?inspect ?exn ?section ?location ?logger ~level:Error msg);
87-
match exn with Some exn -> raise exn | None -> failwith msg
88-
89-
let raise_error_f ?inspect ?exn ?section ?location ?logger fmt =
90-
Printf.ksprintf (raise_error ?inspect ?exn ?section ?location ?logger) fmt
84+
let raise_error ?inspect ?exn ?section ?location ?logger fmt =
85+
let k msg =
86+
Lwt.ignore_result
87+
(Lwt_log.log ?inspect ?exn ?section ?location ?logger ~level:Error msg);
88+
match exn with Some exn -> raise exn | None -> failwith msg
89+
in
90+
Printf.ksprintf k fmt
9191

9292
let eliom_logs_src = Lwt_log.Section.make "eliom"
9393

src/lib/eliom_lib.client.mli

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,6 @@ val raise_error :
8282
-> ?section:Lwt_log.section
8383
-> ?location:string * int * int
8484
-> ?logger:Lwt_log.logger
85-
-> string
86-
-> 'a
87-
88-
val raise_error_f :
89-
?inspect:'v
90-
-> ?exn:exn
91-
-> ?section:Lwt_log.section
92-
-> ?location:string * int * int
93-
-> ?logger:Lwt_log.logger
9485
-> ('a, unit, string, 'any) format4
9586
-> 'a
9687

0 commit comments

Comments
 (0)