From 0646e2f0de557bfa4ed3aea25122180238ac688e Mon Sep 17 00:00:00 2001 From: Ambre Austen Suhamy Date: Wed, 24 May 2023 10:54:51 +0200 Subject: [PATCH] Nitpick: cleaner exception handling in scanf_opt --- pipeline/cb-schema/schema.ml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pipeline/cb-schema/schema.ml b/pipeline/cb-schema/schema.ml index d5e1129b..8f9810e8 100644 --- a/pipeline/cb-schema/schema.ml +++ b/pipeline/cb-schema/schema.ml @@ -1,8 +1,12 @@ (* Added because it was introduced to stdlib in 5.0 *) -let sscanf_opt fmt fn ~str = try Some (Scanf.sscanf str fmt fn) with _ -> None +let sscanf_opt fmt fn ~str = + try Some (Scanf.sscanf str fmt fn) + with Scanf.Scan_failure _ | Failure _ | End_of_file -> None (* Added because it isn't available in reason for some reason *) let option_value default = function None -> default | Some x -> x + +(* Added for convenience *) let option_or o f = match o with Some x -> x | None -> f () let ( >>? ) = option_or