Skip to content

Commit dcb7f52

Browse files
committed
Better error message when ocamlformat emit source triggering warning 50
1 parent 722480c commit dcb7f52

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/Translation_unit.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ module Error = struct
6262
let print_internal_error ~debug ~quiet fmt e =
6363
let s =
6464
match e with
65+
| `Cannot_parse (Parse_with_comments.Warning50 _) ->
66+
"generating invalid comment attachment"
6567
| `Cannot_parse _ -> "generating invalid ocaml syntax"
6668
| `Ast_changed -> "ast changed"
6769
| `Comment _ -> "comment changed"
@@ -72,6 +74,12 @@ module Error = struct
7274
| `Comment x when not quiet -> Cmt.pp_error fmt x
7375
| `Cannot_parse ((Syntaxerr.Error _ | Lexer.Error _) as exn) ->
7476
if debug then Location.report_exception fmt exn
77+
| `Cannot_parse (Parse_with_comments.Warning50 _) ->
78+
(* Printing the warning is not useful because it doesn't reference
79+
the right filename *)
80+
()
81+
| `Cannot_parse exn ->
82+
if debug then Format.fprintf fmt "%s" (Stdlib.Printexc.to_string exn)
7583
| `Warning50 (l, w) -> if debug then Warning.print_warning l w
7684
| _ -> ()
7785

0 commit comments

Comments
 (0)