Print readable error messages in doc code blocks
When parsing fails inside a `{@ocaml[...]}` block, the catch-all branch
formatted the exception with `Exn.pp`, which for `Lexer.Error` produced
the raw constructor pattern
`Ocamlformat_parser_extended.Lexer.Error(_, _)`. `Lexer.Error` (and most
other compiler-libs exceptions) register a printer via
`Location.register_error_of_exn`, but that table is separate from the
`Printexc` table `Exn.pp` consults, so the printer was never used.
Route the catch-all through `Location.error_of_exn` instead: if a
printer is registered, format its `main` message; otherwise fall back to
`Exn.pp`. This handles `Lexer.Error` and any other registered exception
(e.g. parser internals) without per-variant enumeration.
The .err diff against the previous commit shows the before/after for the
six variants the regression test exercises.
0b8ec2
-
May 26 09:37 +00:00