Skip to content

Commit

Permalink
Use native exceptions instead of lwt exceptions to get backtraces mor…
Browse files Browse the repository at this point in the history
…e often
  • Loading branch information
kit-ty-kate committed Dec 2, 2021
1 parent 6254f15 commit 39b14a5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions lib/oca_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let get_files dirname =
aux (file :: files)
end begin function
| End_of_file -> Lwt.return files
| exn -> Lwt.fail exn
| exn -> raise exn
end
in
aux [] >>= fun files ->
Expand Down Expand Up @@ -66,12 +66,12 @@ let pread ?cwd ?exit1 ~timeout cmd f =
| _, _ ->
let cmd = String.concat " " cmd in
prerr_endline ("Command '"^cmd^"' failed (exit status: "^string_of_int n^".");
Lwt.fail (Failure "process failure")
failwith "process failure"
end
| Unix.WSIGNALED n | Unix.WSTOPPED n ->
let cmd = String.concat " " cmd in
prerr_endline ("Command '"^cmd^"' killed by a signal (n°"^string_of_int n^")");
Lwt.fail (Failure "process failure")
failwith "process failure"
end

let read_unordered_lines c =
Expand Down Expand Up @@ -118,7 +118,7 @@ let mkdir_p dir =
Lwt_unix.mkdir (Fpath.to_string dir) 0o750
end begin function
| Unix.Unix_error (Unix.EEXIST, _, _) -> Lwt.return_unit
| e -> Lwt.fail e
| e -> raise e
end [@ocaml.warning "-fragile-match"] >>= fun () ->
aux dir xs
in
Expand All @@ -144,7 +144,7 @@ let rec rm_rf dirname =
in
Lwt.catch rm_files begin function
| End_of_file -> Lwt.return_unit
| e -> Lwt.fail e
| e -> raise e
end
end begin fun () ->
Lwt_unix.closedir dir >>= fun () ->
Expand Down
14 changes: 7 additions & 7 deletions server/backend/admin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let admin_action ~on_finished ~conf ~run_trigger workdir body =
| ["set-processes"; i] ->
let i = int_of_string i in
if i < 0 then
Lwt.fail_with "Cannot set the number of processes to a negative value."
failwith "Cannot set the number of processes to a negative value."
else
Server_configfile.set_processes conf i >|= fun () ->
(fun () -> Lwt.return_none)
Expand Down Expand Up @@ -112,7 +112,7 @@ let admin_action ~on_finished ~conf ~run_trigger workdir body =
| ["log"] ->
get_log workdir
| _ ->
Lwt.fail_with "Action unrecognized."
failwith "Action unrecognized."
end >>= fun resp ->
let stream = Lwt_stream.from resp in
Cohttp_lwt_unix.Server.respond ~status:`OK ~body:(`Stream stream) ()
Expand Down Expand Up @@ -143,20 +143,20 @@ let callback ~on_finished ~conf ~run_trigger workdir _conn _req body =
| Some (pversion, body) when String.equal Oca_lib.protocol_version pversion ->
begin match String.Split.left ~by:"\n" body with
| Some (_, "") ->
Lwt.fail_with "Empty message"
failwith "Empty message"
| Some (user, body) ->
get_user_key workdir user >>= fun key ->
let body = decrypt key body in
begin match String.Split.left ~by:"\n" body with
| Some (user', body) when String.equal user user' ->
admin_action ~on_finished ~conf ~run_trigger workdir body
| Some _ ->
Lwt.fail_with "Identity couldn't be ensured"
failwith "Identity couldn't be ensured"
| None ->
Lwt.fail_with "Identity check required"
failwith "Identity check required"
end
| None ->
Lwt.fail_with "Cannot find username"
failwith "Cannot find username"
end
| Some (pversion, _) ->
Cohttp_lwt_unix.Server.respond_string
Expand All @@ -166,4 +166,4 @@ let callback ~on_finished ~conf ~run_trigger workdir _conn _req body =
Please upgrade your client.")
()
| None ->
Lwt.fail_with "Cannot parse request"
failwith "Cannot parse request"
4 changes: 2 additions & 2 deletions server/backend/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ let ocluster_build_str ~debug ~cap ~conf ~base_obuilder ~stderr ~default c =
Lwt.return r
| (Error (), _) ->
match default with
| None -> Lwt.fail_with ("Failure in ocluster: "^c) (* TODO: Replace this with "send message to debug slack webhook" *)
| None -> failwith ("Failure in ocluster: "^c) (* TODO: Replace this with "send message to debug slack webhook" *)
| Some v -> Lwt.return v

let failure_kind logfile =
Expand Down Expand Up @@ -410,7 +410,7 @@ let get_cap ~stderr ~cap_file =
Lwt.return sr
| Error _ ->
Lwt_io.write_line stderr "cap file couldn't be loaded" >>= fun () ->
Lwt.fail_with "cap file not found"
failwith "cap file not found"

let run_locked = ref false

Expand Down
2 changes: 1 addition & 1 deletion server/lib/cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ let get_html ~conf self query logdir =

let get_latest_logdir self =
self.logdirs >>= function
| [] -> Lwt.fail Not_found
| [] -> raise Not_found
| logdir::_ -> Lwt.return logdir

let get_html ~conf self query logdir =
Expand Down
2 changes: 1 addition & 1 deletion server/lib/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ module Make (Backend : Backend_intf.S) = struct
(* TODO: Try to understand why it wouldn't do anything before when this was ~on_exn *)
Lwt.catch
(fun () -> callback ~conf backend conn req body)
(fun e -> if debug then prerr_endline (Printexc.get_backtrace () ^ Printexc.to_string e); Lwt.fail e)
(fun e -> if debug then prerr_endline (Printexc.get_backtrace () ^ Printexc.to_string e); raise e)

let tcp_server port callback =
Cohttp_lwt_unix.Server.create
Expand Down

0 comments on commit 39b14a5

Please sign in to comment.