use the Any exception everywhere so we never close the app without closing properly the driver

This commit is contained in:
Mylloon 2023-05-13 18:02:46 +02:00
parent e62a82fc62
commit 3427d3b079
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 9 additions and 9 deletions

View file

@ -2,8 +2,6 @@ open Pusk.Net
open Pusk.Drivers open Pusk.Drivers
open Pusk.Utils open Pusk.Utils
exception Any of string
let start driver = let start driver =
let name_driver = prepare driver in let name_driver = prepare driver in
let data_driver = run_process name_driver [] in let data_driver = run_process name_driver [] in

View file

@ -15,7 +15,7 @@ let rec download uri dest =
let uri = Uri.of_string url in let uri = Uri.of_string url in
let redirect_url = Uri.resolve "" uri uri in let redirect_url = Uri.resolve "" uri uri in
download redirect_url dest download redirect_url dest
| None -> failwith "Redirect location not found") | None -> raise (Any "Redirect location not found"))
else if Cohttp.Code.is_success code else if Cohttp.Code.is_success code
then ( then (
print_endline "Downloading..."; print_endline "Downloading...";
@ -28,8 +28,8 @@ let rec download uri dest =
print_endline "Download done!"; print_endline "Download done!";
Lwt.return_unit) Lwt.return_unit)
else else
failwith raise
("Failed to download file. HTTP status: " ^ Cohttp.Code.string_of_status status) (Any ("Failed to download file. HTTP status: " ^ Cohttp.Code.string_of_status status))
;; ;;
let download_gecko_driver version output = let download_gecko_driver version output =

View file

@ -37,10 +37,10 @@ let get_session () =
let rec find_session_id = function let rec find_session_id = function
| ("sessionId", `String session_id) :: _ -> session_id | ("sessionId", `String session_id) :: _ -> session_id
| _ :: rest -> find_session_id rest | _ :: rest -> find_session_id rest
| [] -> failwith "Session ID not found" | [] -> raise (Any "Session ID not found")
in in
find_session_id (Yojson.Safe.Util.to_assoc value) find_session_id (Yojson.Safe.Util.to_assoc value)
| _ -> failwith "get_session | Invalid JSON" | _ -> raise (Any "get_session | Invalid JSON")
;; ;;
let close_session id = execute_delete_request (driver id) = "{\"value\":null}" let close_session id = execute_delete_request (driver id) = "{\"value\":null}"
@ -61,8 +61,8 @@ let rec wait_for_load session_id =
then ( then (
Unix.sleep 1; Unix.sleep 1;
wait_for_load session_id) wait_for_load session_id)
| _ -> failwith "Error when waiting for page to load") | _ -> raise (Any "Error when waiting for page to load"))
| _ -> failwith "wait_for_load | Invalid JSON" | _ -> raise (Any "wait_for_load | Invalid JSON")
;; ;;
let navigate ?(wait = true) url session_id = let navigate ?(wait = true) url session_id =

View file

@ -1,3 +1,5 @@
exception Any of string
let fmt = Printf.sprintf let fmt = Printf.sprintf
let load_dotenv = let load_dotenv =