Skip to content

Commit

Permalink
Handle exception when trying to unescape default message
Browse files Browse the repository at this point in the history
  • Loading branch information
cknitt committed Sep 4, 2023
1 parent 94bd887 commit 11414b6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11414b6

Please sign in to comment.