Skip to content

Commit c623ff7

Browse files
Julowsmorimoto
authored andcommitted
Eliom_lib: Remove Lwt_log redefinition
This is a minor refactoring of Eliom_lib to prepare for the migration to Logs. Eliom's log section is moved from `Eliom_lib.Lwt_log.eliom` to `Eliom_lib.eliom_logs_src`. The name was choosen with Logs in mind. In the client version of the lib, `raise_error` and `raise_errorf` are moved to the toplevel namespace.
1 parent 7468972 commit c623ff7

19 files changed

+83
-113
lines changed

eliom.opam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception"
1717
homepage: "https://ocsigen.org/eliom/"
1818
bug-reports: "https://github.com/ocsigen/eliom/issues"
1919
depends: [
20-
"dune" {>= "3.6"}
20+
"dune" {>= "3.18"}
2121
"ocaml" {>= "4.12" & < "5.3"}
2222
"ocamlfind"
2323
"ppx_deriving"
@@ -56,3 +56,4 @@ build: [
5656
]
5757
]
5858
dev-repo: "git+https://github.com/ocsigen/eliom.git"
59+
x-maintenance-intent: ["(latest)"]

src/lib/client/eliommod_dom.ml

Lines changed: 6 additions & 8 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-
Lwt_log.raise_error_f ~section "%s element tagged as eliom link"
251+
raise_error_f ~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);
@@ -302,12 +302,12 @@ end
302302
let get_head (page : 'element #get_tag Js.t) : 'element Js.t =
303303
Js.Opt.get
304304
page ## (getElementsByTagName (Js.string "head")) ## (item 0)
305-
(fun () -> Lwt_log.raise_error ~section "get_head")
305+
(fun () -> raise_error ~section "get_head")
306306

307307
let get_body (page : 'element #get_tag Js.t) : 'element Js.t =
308308
Js.Opt.get
309309
page ## (getElementsByTagName (Js.string "body")) ## (item 0)
310-
(fun () -> Lwt_log.raise_error ~section "get_body")
310+
(fun () -> raise_error ~section "get_body")
311311

312312
let iter_dom_array (f : 'a -> unit)
313313
(a :
@@ -349,7 +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-
Lwt_log.raise_error_f ~section
352+
raise_error_f ~section
353353
"add_childrens: not text node in tag %s"
354354
(Js.to_string elt##.tagName)
355355
in
@@ -368,7 +368,7 @@ let add_childrens (elt : Dom_html.element Js.t) (sons : Dom.node Js.t list) =
368368
let d = Dom_html.createHead Dom_html.document in
369369
Dom.appendChild d elt;
370370
(Js.Unsafe.coerce elt)##.styleSheet##.cssText := concat sons
371-
| _ -> Lwt_log.raise_error ~section ~exn "add_childrens: can't appendChild")
371+
| _ -> raise_error ~section ~exn "add_childrens: can't appendChild")
372372

373373
(* END IE HACK *)
374374

@@ -413,9 +413,7 @@ let copy_element (e : Dom.element Js.t)
413413
add_childrens copy child_copies;
414414
Some copy
415415
in
416-
match aux e with
417-
| None -> Lwt_log.raise_error ~section "copy_element"
418-
| Some e -> e
416+
match aux e with None -> raise_error ~section "copy_element" | Some e -> e
419417

420418
let html_document (src : Dom.element Dom.document Js.t) registered_process_node
421419
: Dom_html.element Js.t

src/lib/eliom_bus.client.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ let original_stream t =
137137
if Eliom_client_core.in_onload () && t.original_stream_available
138138
then stream t
139139
else
140-
Lwt_log.raise_error ~section
140+
raise_error ~section
141141
"original_stream: the original stream is not available anymore"
142142

143143
let flush t =

src/lib/eliom_client.client.ml

Lines changed: 8 additions & 12 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-
Lwt_log.raise_error_f ~section "not an anchor element")
182+
raise_error_f ~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-
Lwt_log.raise_error_f ~section "not a form element")
199+
raise_error_f ~section "not a form element")
200200
in
201201
let kind =
202202
if String.lowercase_ascii (Js.to_string form##._method) = "get"
@@ -213,8 +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 () ->
217-
Lwt_log.raise_error_f ~section "unique node without id attribute")
216+
(fun () -> raise_error_f ~section "unique node without id attribute")
218217
in
219218
Js.Optdef.case
220219
(Eliom_client_core.find_process_node id)
@@ -241,8 +240,7 @@ let relink_request_node (node : Dom_html.element Js.t) =
241240
let id =
242241
Js.Opt.get
243242
node ## (getAttribute (Js.string Eliom_runtime.RawXML.node_id_attrib))
244-
(fun () ->
245-
Lwt_log.raise_error_f ~section "unique node without id attribute")
243+
(fun () -> raise_error_f ~section "unique node without id attribute")
246244
in
247245
Js.Optdef.case
248246
(Eliom_client_core.find_request_node id)
@@ -375,8 +373,7 @@ let relink_attrib _root table (node : Dom_html.element Js.t) =
375373
in
376374
Eliom_client_core.rebuild_rattrib node rattrib
377375
with Not_found ->
378-
Lwt_log.raise_error_f ~section
379-
"relink_attrib: client value %s not found" cid
376+
raise_error_f ~section "relink_attrib: client value %s not found" cid
380377
in
381378
Eliommod_dom.iter_attrList node##.attributes aux
382379

@@ -401,11 +398,10 @@ let load_data_script page =
401398
match Js.to_bytestring data_script##.tagName##toLowerCase with
402399
| "script" -> Js.Unsafe.coerce data_script
403400
| t ->
404-
Lwt_log.raise_error_f ~section
401+
raise_error_f ~section
405402
"Unable to find Eliom application data (script element expected, found %s element)"
406403
t)
407-
| _ ->
408-
Lwt_log.raise_error_f ~section "Unable to find Eliom application data."
404+
| _ -> raise_error_f ~section "Unable to find Eliom application data."
409405
in
410406
let script = data_script##.text in
411407
if !Eliom_config.debug_timings
@@ -826,7 +822,7 @@ let get_state state_id : state =
826822
(* We use this only when the history API is
827823
available. Sessionstorage seems to be available
828824
everywhere the history API exists. *)
829-
Lwt_log.raise_error_f ~section "sessionStorage not available")
825+
raise_error_f ~section "sessionStorage not available")
830826
(fun s -> s ## (getItem (state_key state_id))))
831827
(fun () -> raise Not_found)
832828
(fun s -> of_json ~typ:[%json: state] (Js.to_string s))

src/lib/eliom_client_core.client.ml

Lines changed: 7 additions & 7 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-
Lwt_log.raise_error_f ~section
90+
raise_error_f ~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-
Lwt_log.raise_error_f "Did not find injection %s" name))
139+
raise_error_f "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-
Lwt_log.raise_error_f ~section
171+
raise_error_f ~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-
Lwt_log.raise_error_f ~section
187+
raise_error_f ~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 -> ()
@@ -361,7 +361,7 @@ let reify_caml_event name node ce =
361361
(fun ev ->
362362
let node =
363363
Js.Opt.get (Dom_html.CoerceTo.a node) (fun () ->
364-
Lwt_log.raise_error ~section "not an anchor element")
364+
raise_error ~section "not an anchor element")
365365
in
366366
raw_a_handler node cookies_info tmpl ev) )
367367
| Xml.CE_call_service
@@ -373,7 +373,7 @@ let reify_caml_event name node ce =
373373
(fun ev ->
374374
let form =
375375
Js.Opt.get (Dom_html.CoerceTo.form node) (fun () ->
376-
Lwt_log.raise_error ~section "not a form element")
376+
raise_error ~section "not a form element")
377377
in
378378
raw_form_handler form kind cookies_info tmpl ev
379379
(Eliom_lib.from_poly client_hdlr : client_form_handler)) )
@@ -732,7 +732,7 @@ let rebuild_node_ns ns context elt' =
732732
elt' context;
733733
if is_before_initial_load ()
734734
then
735-
Lwt_log.raise_error_f ~section ~inspect:(rebuild_node' ns elt')
735+
raise_error_f ~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: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ open Lwt.Syntax
2424
(* This file is for client-side comet-programming. *)
2525

2626
open Js_of_ocaml
27+
open Eliom_lib
2728
module Ecb = Eliom_comet_base
2829

29-
let section = Eliom_lib.Lwt_log.Section.make "eliom:comet"
30+
let section = Lwt_log.Section.make "eliom:comet"
3031

3132
module Configuration = struct
3233
type configuration_data =
@@ -184,8 +185,8 @@ let handle_exn, set_handle_exn_function =
184185
"Unknown exception during comet. Customize this with Eliom_comet.set_handle_exn_function. "
185186
in
186187
match exn with
187-
| Some exn -> Eliom_lib.Lwt_log.raise_error ~section ~exn s
188-
| None -> Eliom_lib.Lwt_log.debug ~section s)
188+
| Some exn -> raise_error ~section ~exn s
189+
| None -> Lwt_log.debug ~section s)
189190
in
190191
( (fun ?exn () ->
191192
if not !closed
@@ -408,7 +409,7 @@ end = struct
408409
(function
409410
| _chan_id, Ecb.Data _ -> ()
410411
| _chan_id, Ecb.Closed ->
411-
Eliom_lib.Lwt_log.ign_warning ~section
412+
Lwt_log.ign_warning ~section
412413
"update_stateful_state: received Closed: should not happen, this is an eliom bug, please report it"
413414
| chan_id, Ecb.Full -> stop_waiting hd chan_id)
414415
message
@@ -524,17 +525,17 @@ end = struct
524525
| Eliom_request.Failed_request (0 | 502 | 504) ->
525526
if retries > max_retries
526527
then (
527-
Eliom_lib.Lwt_log.ign_notice ~section "connection failure";
528+
Lwt_log.ign_notice ~section "connection failure";
528529
set_activity hd `Inactive;
529530
aux 0)
530531
else
531532
let* () = Js_of_ocaml_lwt.Lwt_js.sleep (delay retries) in
532533
aux (retries + 1)
533534
| Restart ->
534-
Eliom_lib.Lwt_log.ign_info ~section "restart";
535+
Lwt_log.ign_info ~section "restart";
535536
aux 0
536537
| exn ->
537-
Eliom_lib.Lwt_log.ign_notice ~exn ~section "connection failure";
538+
Lwt_log.ign_notice ~exn ~section "connection failure";
538539
let* () = handle_exn ~exn () in
539540
Lwt.fail exn)
540541
in
@@ -547,7 +548,7 @@ end = struct
547548
call_service_after_load_end srv queue
548549
(false, Ecb.Stateful (Ecb.Commands command)))
549550
(fun exn ->
550-
Eliom_lib.Lwt_log.ign_notice_f ~section ~exn "request failed";
551+
Lwt_log.ign_notice_f ~section ~exn "request failed";
551552
Lwt.return ""))
552553

553554
let close hd chan_id =
@@ -566,8 +567,8 @@ end = struct
566567
{state with count = state.count - 1}
567568
!map
568569
with Not_found ->
569-
Eliom_lib.Lwt_log.ign_info_f ~section
570-
"trying to close a non existent channel: %s" chan_id)
570+
Lwt_log.ign_info_f ~section "trying to close a non existent channel: %s"
571+
chan_id)
571572

572573
let add_channel_stateful hd chan_id =
573574
hd.hd_activity.active_channels <-
@@ -580,7 +581,7 @@ end = struct
580581
| Ecb.Last i, Ecb.Last j -> Ecb.Last (max i j)
581582
| p, Ecb.Last _ -> p
582583
| Ecb.Last _, p -> p
583-
| _ -> Eliom_lib.Lwt_log.raise_error ~section "not corresponding position"
584+
| _ -> raise_error ~section "not corresponding position"
584585

585586
let add_channel_stateless hd chan_id kind =
586587
let pos =
@@ -714,7 +715,7 @@ let check_and_update_position position msg_pos data =
714715
match position, msg_pos, data with
715716
| No_position, None, _ -> true
716717
| No_position, Some _, _ | Position _, None, Ecb.Data _ ->
717-
Eliom_lib.Lwt_log.raise_error ~section
718+
raise_error ~section
718719
"check_position: channel kind and message do not match"
719720
| Position _, None, (Ecb.Full | Ecb.Closed) -> true
720721
| Position (relation, r), Some j, _ -> (

src/lib/eliom_common.server.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let tenable_value ~name v =
4848
value <- v;
4949
tenable <- override_tenable)
5050
else
51-
Lwt_log.ign_warning_f ~section:Lwt_log.eliom
51+
Lwt_log.ign_warning_f ~section:eliom_logs_src
5252
"Ignored setting tenable value %S." name
5353
end
5454

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-
Lwt_log.raise_error_f ~section:Lwt_log.eliom
57+
raise_error_f ~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-
Lwt_log.raise_error_f ~section:Lwt_log.eliom
67+
raise_error_f ~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: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,17 @@ module Url = struct
7979
split_path (try String.(sub s 0 (index s '?')) with Not_found -> s)
8080
end
8181

82-
module Lwt_log = struct
83-
include Lwt_log_js
82+
module Lwt_log = Lwt_log_js
8483

85-
let raise_error ?inspect ?exn ?section ?location ?logger msg =
86-
Lwt.ignore_result
87-
(log ?inspect ?exn ?section ?location ?logger ~level:Error msg);
88-
match exn with Some exn -> raise exn | None -> failwith msg
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
8988

90-
let raise_error_f ?inspect ?exn ?section ?location ?logger fmt =
91-
Printf.ksprintf (raise_error ?inspect ?exn ?section ?location ?logger) fmt
89+
let raise_error_f ?inspect ?exn ?section ?location ?logger fmt =
90+
Printf.ksprintf (raise_error ?inspect ?exn ?section ?location ?logger) fmt
9291

93-
let eliom = Section.make "eliom"
94-
end
92+
let eliom_logs_src = Lwt_log.Section.make "eliom"
9593

9694
let _ =
9795
Lwt_log.default := Lwt_log.console;

0 commit comments

Comments
 (0)