Source locations and structured errors for text codecs (extracted from jsont)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

claude: complete Err -> Error module rename across call sites

Follow up to the module rename: update the remaining callers that
still referenced [Err] (library [claude.ml{,i}], [client.ml], the test
driver [test.ml]), and fix one stray [^ e] string concatenation in
hermest's CLI that needed [Json.Error.to_string e] now that
[Json.of_string] yields a structured error.

+14 -14
+7 -2
lib/loc.ml
··· 327 327 let push_mem sort n ctx = push ~sort (Path.Mem n) ctx 328 328 let push_array = push_nth 329 329 let push_object = push_mem 330 + 330 331 (* Context's raw storage is ROOT-to-LEAF: the push-on-way-up semantics 331 332 used by decoders (inner catcher fires first, outer last) means outer 332 333 frames are consed LAST, so they sit at the head. Path's raw storage 333 334 is LEAF-to-ROOT (cons at head during descent) -- the conventions 334 335 mirror each other. Accessors bridge the two. *) 335 - let last_step ctx = match List.rev ctx with [] -> None | f :: _ -> Some f.step 336 - let last_sort ctx = match List.rev ctx with [] -> None | f :: _ -> Some f.sort 336 + let last_step ctx = 337 + match List.rev ctx with [] -> None | f :: _ -> Some f.step 338 + 339 + let last_sort ctx = 340 + match List.rev ctx with [] -> None | f :: _ -> Some f.sort 341 + 337 342 let frames ctx = List.map (fun f -> (f.sort, f.step)) ctx 338 343 let rev_frames ctx = List.rev (frames ctx) 339 344
+4 -4
lib/loc.mli
··· 317 317 [None] at the root. *) 318 318 319 319 val frames : t -> (string node * Path.step) list 320 - (** [frames ctx] is the list of [(sort, step)] frames in root-to-leaf 321 - order. *) 320 + (** [frames ctx] is the list of [(sort, step)] frames in root-to-leaf order. 321 + *) 322 322 323 323 val rev_frames : t -> (string node * Path.step) list 324 324 (** [rev_frames ctx] is the list of [(sort, step)] frames in leaf-to-root 325 - order (the raw internal order). Cheaper than {!frames}; use when 326 - iteration order is irrelevant. *) 325 + order (the raw internal order). Cheaper than {!frames}; use when iteration 326 + order is irrelevant. *) 327 327 328 328 (** {2:compat Legacy push helpers} *) 329 329
+3 -8
test/test_loc.ml
··· 203 203 let meta_of_sample = Loc.Meta.make sample 204 204 205 205 let error_msg () = 206 - let e = 207 - Loc.Error.msg ~ctx:Loc.Context.empty ~meta:meta_of_sample "boom" 208 - in 206 + let e = Loc.Error.msg ~ctx:Loc.Context.empty ~meta:meta_of_sample "boom" in 209 207 let s = Loc.Error.to_string e in 210 208 Alcotest.(check bool) "contains msg" true (contains_substring "boom" s); 211 209 Alcotest.(check bool) "contains file" true (contains_substring "foo.ml" s) ··· 236 234 (contains_substring "found string" s) 237 235 238 236 let error_push_context () = 239 - let e = 240 - Loc.Error.msg ~ctx:Loc.Context.empty ~meta:meta_of_sample "bad" 241 - in 237 + let e = Loc.Error.msg ~ctx:Loc.Context.empty ~meta:meta_of_sample "bad" in 242 238 let kinded = ("array", Loc.Meta.none) in 243 239 let n = (3, Loc.Meta.none) in 244 240 try ··· 246 242 Alcotest.fail "expected Error" 247 243 with Loc.Error e -> 248 244 let ctx = Loc.Error.ctx e in 249 - Alcotest.(check bool) 250 - "ctx non-empty" false (Loc.Context.is_empty ctx); 245 + Alcotest.(check bool) "ctx non-empty" false (Loc.Context.is_empty ctx); 251 246 Alcotest.(check int) 252 247 "one layer" 1 253 248 (List.length (Loc.Path.rev_steps (Loc.Context.path ctx)))