From fe7c2d759549772a2c58f7941d17effca65fcc83 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 17 Sep 2013 18:15:24 +0100 Subject: [PATCH] On goal failure, exit with correct error message and error code. --- goaljobs.ml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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; -- 1.8.3.1