From 11414b6eebb09f81a37991d039e5f8b284aaca68 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 4 Sep 2023 14:25:17 +0200 Subject: [PATCH] Handle exception when trying to unescape default message --- lib/Message.ml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Message.ml b/lib/Message.ml index 02ed7d5..fb0abc8 100644 --- a/lib/Message.ml +++ b/lib/Message.ml @@ -13,8 +13,14 @@ let fromStringMap ?description map = | Some id, Some defaultMessage -> Some {id; defaultMessage; description} | _ -> None +let tryUnescape s = + try Scanf.unescaped s + with Scanf.Scan_failure err -> + (* ignore and return original string instead *) + s + let toJson {id; defaultMessage; description} : Yojson.Basic.t = - let defaultMessage = Scanf.unescaped defaultMessage in + let defaultMessage = tryUnescape defaultMessage in match description with | Some description -> `Assoc