diff --git a/src/stdune/scanf.ml b/src/stdune/scanf.ml index cd00486dad47..df8dc40362b6 100644 --- a/src/stdune/scanf.ml +++ b/src/stdune/scanf.ml @@ -1,13 +1,12 @@ module Scanf = Dune_caml.Scanf -let unescaped x = - match Scanf.unescaped x with +let try_ f = + match f () with | exception End_of_file -> Error () | exception Scanf.Scan_failure _ -> Error () + | exception (Failure _) -> Error () | x -> Ok x -let sscanf x fmt f = - match Scanf.sscanf x fmt f with - | exception End_of_file -> Error () - | exception Scanf.Scan_failure _ -> Error () - | x -> Ok x +let unescaped x = try_ (fun () -> Scanf.unescaped x) + +let sscanf x fmt f = try_ (fun () -> Scanf.sscanf x fmt f)