Skip to content

Commit ee57ac1

Browse files
committed
fix(CLI): Report JSON parse error origin and locations
1 parent 57ca10b commit ee57ac1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/repo/learnocaml_process_common.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,17 @@ let to_file encoding fn value =
1515
let from_file encoding fn =
1616
Lwt_io.(with_file ~mode: Input) fn @@ fun chan ->
1717
Lwt_io.read chan >>= fun str ->
18-
let json = Ezjsonm.from_string str in
18+
let json =
19+
match Ezjsonm.from_string_result str with
20+
| Ok json -> json
21+
| Error err ->
22+
let loc = match Ezjsonm.read_error_location err with
23+
| None -> fn
24+
| Some ((li, col), _) ->
25+
Printf.sprintf "%s, line %d, column %d" fn li col
26+
in
27+
Printf.ksprintf failwith
28+
"Parse error in %s:\n %s" loc
29+
(Ezjsonm.read_error_description err);
30+
in
1931
Lwt.return (Json_encoding.destruct encoding json)

0 commit comments

Comments
 (0)