Skip to content

Commit 696488f

Browse files
committed
include proper error-handling in the README example
1 parent 1cc8dfb commit 696488f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ Example usage
99

1010
```ocaml
1111
let tmpl =
12-
Mustache.of_string "Hello {{name}}\n\
13-
Mustache is:\n\
14-
{{#qualities}}\
15-
* {{name}}\n\
16-
{{/qualities}}"
12+
try
13+
Mustache.of_string "Hello {{name}}\n\
14+
Mustache is:\n\
15+
{{#qualities}}\
16+
* {{name}}\n\
17+
{{/qualities}}"
18+
with Mustache.Parse_error err ->
19+
Format.eprintf "%a@."
20+
Mustache.pp_template_parse_error err;
21+
exit 3
1722
1823
let json =
1924
`O [ "name", `String "OCaml"
@@ -24,7 +29,11 @@ let json =
2429
]
2530
2631
let rendered =
27-
Mustache.render tmpl json
32+
try Mustache.render tmpl json
33+
with Mustache.Render_error err ->
34+
Format.eprintf "%a@."
35+
Mustache.pp_render_error err;
36+
exit 2
2837
```
2938

3039
Spec compliance

0 commit comments

Comments
 (0)