diff options
author | G.raud <graud@gmx.com> | 2018-02-01 06:53:41 +0100 |
---|---|---|
committer | G.raud <graud@gmx.com> | 2018-02-02 08:28:28 +0100 |
commit | dd964036b906b6a6dfa7d947809849a68d9834ca (patch) | |
tree | fd3a818d971be71fd057f4af8a8bd87f908186e8 /src | |
parent | 77885be3740480136c2749ea11dd37a6ca1a18cd (diff) | |
download | unison-dd964036b906b6a6dfa7d947809849a68d9834ca.zip unison-dd964036b906b6a6dfa7d947809849a68d9834ca.tar.gz unison-dd964036b906b6a6dfa7d947809849a68d9834ca.tar.bz2 |
Uarg: fail cleanly when a value to an option has not the expected type
Diffstat (limited to 'src')
-rw-r--r-- | src/ubase/uarg.ml | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/ubase/uarg.ml b/src/ubase/uarg.ml index f2e5444..2d9e55e 100644 --- a/src/ubase/uarg.ml +++ b/src/ubase/uarg.ml @@ -83,6 +83,9 @@ let parse speclist anonfun errmsg = let action = try assoc3 s speclist with Not_found -> stop (Unknown s) + and catch f a = + try f a + with Invalid_argument s -> raise (Failure s) in begin try match action with @@ -92,11 +95,11 @@ let parse speclist anonfun errmsg = | Bool f -> begin match args with [_] -> f true - | _ -> f (arg bool_of_string "a boolean") + | _ -> f (arg (catch bool_of_string) "a boolean") end | String f -> f (arg (fun s-> s) "") - | Int f -> f (arg int_of_string "an integer") - | Float f -> f (arg float_of_string "a float") + | Int f -> f (arg (catch int_of_string) "an integer") + | Float f -> f (arg (catch float_of_string) "a float") | Rest f -> while !current < l-1 do f argv.(!current+1); |