9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-07 14:03:37 +01:00

Better error handling on ocaml
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Anthony Scemama 2022-06-18 11:39:36 +02:00
parent d11b7365cb
commit a0949cba45
5 changed files with 22 additions and 14 deletions

View File

@ -80,8 +80,6 @@ function qp()
if [[ -d $NAME ]] ; then if [[ -d $NAME ]] ; then
[[ -d $EZFIO_FILE ]] && ezfio unset_file [[ -d $EZFIO_FILE ]] && ezfio unset_file
ezfio set_file $NAME ezfio set_file $NAME
else
qp_create_ezfio -h | more
fi fi
unset _ARGS unset _ARGS
;; ;;

@ -1 +1 @@
Subproject commit 242151e03d1d6bf042387226431d82d35845686a Subproject commit 90ee61f5041c7c94a0c605625a264860292813a0

View File

@ -1,3 +1,5 @@
exception Error of string
type short_opt = char type short_opt = char
type long_opt = string type long_opt = string
type optional = Mandatory | Optional type optional = Mandatory | Optional
@ -181,15 +183,16 @@ let set_specs specs_in =
Getopt.parse_cmdline cmd_specs (fun x -> anon_args := !anon_args @ [x]); Getopt.parse_cmdline cmd_specs (fun x -> anon_args := !anon_args @ [x]);
if show_help () then if show_help () then
(help () ; exit 0); help ()
else
(* Check that all mandatory arguments are set *) (* Check that all mandatory arguments are set *)
List.filter (fun x -> x.short <> ' ' && x.opt = Mandatory) !specs List.filter (fun x -> x.short <> ' ' && x.opt = Mandatory) !specs
|> List.iter (fun x -> |> List.iter (fun x ->
match get x.long with match get x.long with
| Some _ -> () | Some _ -> ()
| None -> failwith ("Error: --"^x.long^" option is missing.") | None -> raise (Error ("--"^x.long^" option is missing."))
) )
;; ;;

View File

@ -59,6 +59,8 @@ let () =
*) *)
exception Error of string
type short_opt = char type short_opt = char
type long_opt = string type long_opt = string

View File

@ -677,6 +677,7 @@ let run ?o b au c d m p cart xyz_file =
let () = let () =
try (
let open Command_line in let open Command_line in
begin begin
@ -734,7 +735,7 @@ If a file with the same name as the basis set exists, this file will be read. O
let basis = let basis =
match Command_line.get "basis" with match Command_line.get "basis" with
| None -> assert false | None -> ""
| Some x -> x | Some x -> x
in in
@ -773,10 +774,14 @@ If a file with the same name as the basis set exists, this file will be read. O
let xyz_filename = let xyz_filename =
match Command_line.anon_args () with match Command_line.anon_args () with
| [x] -> x | [] -> failwith "input file is missing"
| _ -> (Command_line.help () ; failwith "input file is missing") | x::_ -> x
in in
run ?o:output basis au charge dummy multiplicity pseudo cart xyz_filename run ?o:output basis au charge dummy multiplicity pseudo cart xyz_filename
)
with
| Failure txt -> Printf.eprintf "Fatal error: %s\n%!" txt
| Command_line.Error txt -> Printf.eprintf "Command line error: %s\n%!" txt