From: Richard W.M. Jones Date: Tue, 17 Sep 2013 17:15:24 +0000 (+0100) Subject: On goal failure, exit with correct error message and error code. X-Git-Tag: 0.2~25 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=fe7c2d759549772a2c58f7941d17effca65fcc83;p=goaljobs.git On goal failure, exit with correct error message and error code. --- diff --git a/goaljobs.ml b/goaljobs.ml index 6875ca5..4a66780 100644 --- a/goaljobs.ml +++ b/goaljobs.ml @@ -428,8 +428,18 @@ let goal_memory_exists k = goal_failed msg ) +let guard fn arg = + try fn arg; true + with + | Goal_result (Goal_failed msg) -> + prerr_endline ("error: " ^ msg); + false + | exn -> + prerr_endline (Printexc.to_string exn); + false + (* Run the program. *) -let init () = +let rec init () = let prog = Sys.executable_name in let prog = Filename.basename prog in @@ -474,10 +484,11 @@ Options: let args = List.rev !args in (* Was a goal named on the command line? *) - match args with + (match args with | name :: args -> (match get_goal name with - | Some fn -> fn args + | Some fn -> + exit (if guard fn args then 0 else 1) | None -> eprintf "error: no goal called '%s' was found.\n" name; eprintf "Use %s -l to list all published goals in this script.\n" name;