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.Utils
exception Any of string
let start driver =
let name_driver = prepare 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 redirect_url = Uri.resolve "" uri uri in
download redirect_url dest
| None -> failwith "Redirect location not found")
| None -> raise (Any "Redirect location not found"))
else if Cohttp.Code.is_success code
then (
print_endline "Downloading...";
@ -28,8 +28,8 @@ let rec download uri dest =
print_endline "Download done!";
Lwt.return_unit)
else
failwith
("Failed to download file. HTTP status: " ^ Cohttp.Code.string_of_status status)
raise
(Any ("Failed to download file. HTTP status: " ^ Cohttp.Code.string_of_status status))
;;
let download_gecko_driver version output =

View file

@ -37,10 +37,10 @@ let get_session () =
let rec find_session_id = function
| ("sessionId", `String session_id) :: _ -> session_id
| _ :: rest -> find_session_id rest
| [] -> failwith "Session ID not found"
| [] -> raise (Any "Session ID not found")
in
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}"
@ -61,8 +61,8 @@ let rec wait_for_load session_id =
then (
Unix.sleep 1;
wait_for_load session_id)
| _ -> failwith "Error when waiting for page to load")
| _ -> failwith "wait_for_load | Invalid JSON"
| _ -> raise (Any "Error when waiting for page to load"))
| _ -> raise (Any "wait_for_load | Invalid JSON")
;;
let navigate ?(wait = true) url session_id =

View file

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