···11+module Error = Model.Error
22+33+44+15let read_string parent_definition location text =
22- Model.Error.catch (fun () ->
66+ Error.catch (fun () ->
37 Attrs.read_string parent_definition location text)
485961077-let corrupted : string -> (_, Model.Error.t) result = fun file ->
88- Error (`With_filename_only {file; error = "corrupted"})
1111+let corrupted : string -> Error.t =
1212+ Error.filename_only "corrupted"
9131010-let not_a_typedtree : string -> (_, Model.Error.t) result = fun file ->
1111- Error (`With_filename_only {file; error = "not a Typedtree"})
1414+let not_a_typedtree : string -> Error.t =
1515+ Error.filename_only "not a Typedtree"
12161313-let not_an_implementation : string -> (_, Model.Error.t) result = fun file ->
1414- Error (`With_filename_only {file; error = "not an implementation"})
1717+let not_an_implementation : string -> Error.t =
1818+ Error.filename_only "not an implementation"
15191616-let not_an_interface : string -> (_, Model.Error.t) result = fun file ->
1717- Error (`With_filename_only {file; error = "not an interface"})
2020+let not_an_interface : string -> Error.t =
2121+ Error.filename_only "not an interface"
18221919-let wrong_version : string -> (_, Model.Error.t) result = fun file ->
2020- Error (`With_filename_only {file; error = "wrong OCaml version"})
2323+let wrong_version : string -> Error.t =
2424+ Error.filename_only "wrong OCaml version"
2125222623272428let read_cmti ~make_root ~filename =
2529 match Cmt_format.read_cmt filename with
2630 | exception Cmi_format.Error (Not_an_interface _) ->
2727- not_an_interface filename
3131+ Error (not_an_interface filename)
2832 | exception Cmt_format.Error (Not_a_typedtree _) ->
2929- not_a_typedtree filename
3333+ Error (not_a_typedtree filename)
3034 | cmt_info ->
3135 match cmt_info.cmt_annots with
3236 | Interface intf ->
3337 begin match cmt_info.cmt_interface_digest with
3434- | None -> corrupted filename
3838+ | None -> Error (corrupted filename)
3539 | Some digest ->
3636- Model.Error.catch begin fun () ->
4040+ Error.catch begin fun () ->
3741 let name = cmt_info.cmt_modname in
3842 let root = make_root ~module_name:name ~digest in
3943 let (id, doc, items) = Cmti.read_interface root name intf in
···5963 interface; hidden; content; expansion = None}
6064 end
6165 end
6262- | _ -> not_an_interface filename
6666+ | _ -> Error (not_an_interface filename)
63676468let read_cmt ~make_root ~filename =
6569 match Cmt_format.read_cmt filename with
6670 | exception Cmi_format.Error (Not_an_interface _) ->
6767- not_an_implementation filename
7171+ Error (not_an_implementation filename)
6872 | exception Cmi_format.Error (Wrong_version_interface _) ->
6969- wrong_version filename
7373+ Error (wrong_version filename)
7074 | exception Cmi_format.Error (Corrupted_interface _) ->
7171- corrupted filename
7575+ Error (corrupted filename)
7276 | exception Cmt_format.Error (Not_a_typedtree _) ->
7373- not_a_typedtree filename
7777+ Error (not_a_typedtree filename)
7478 | cmt_info ->
7579 match cmt_info.cmt_annots with
7680 | Packed(_, files) ->
···114118 source; interface; hidden; content; expansion = None}
115119116120 | Implementation impl ->
117117- Model.Error.catch begin fun () ->
121121+ Error.catch begin fun () ->
118122 let name = cmt_info.cmt_modname in
119123 let interface, digest =
120124 match cmt_info.cmt_interface_digest with
···146150 source; interface; hidden; content; expansion = None}
147151 end
148152149149- | _ -> not_an_implementation filename
153153+ | _ -> Error (not_an_implementation filename)
150154151155let read_cmi ~make_root ~filename =
152156 match Cmi_format.read_cmi filename with
153157 | exception Cmi_format.Error (Not_an_interface _) ->
154154- not_an_interface filename
158158+ Error (not_an_interface filename)
155159 | exception Cmi_format.Error (Wrong_version_interface _) ->
156156- wrong_version filename
160160+ Error (wrong_version filename)
157161 | exception Cmi_format.Error (Corrupted_interface _) ->
158158- corrupted filename
162162+ Error (corrupted filename)
159163 | cmi_info ->
160164 match cmi_info.cmi_crcs with
161165 | (name, Some digest) :: imports when name = cmi_info.cmi_name ->
162162- Model.Error.catch begin fun () ->
166166+ Error.catch begin fun () ->
163167 let root = make_root ~module_name:name ~digest:digest in
164168 let (id, doc, items) = Cmi.read_interface root name cmi_info.cmi_sign in
165169 let imports =
···174178 source; interface; hidden; content; expansion = None}
175179 end
176180177177- | _ -> corrupted filename
181181+ | _ -> Error (corrupted filename)
+11-8
src/model/error.ml
···11type full_location_payload = {
22 location : Location_.span;
33- error : string;
33+ message : string;
44}
5566type filename_only_payload = {
77 file : string;
88- error : string;
88+ message : string;
99}
10101111type t = [
···1919}
20202121let make : string -> Location_.span -> t = fun message location ->
2222- `With_full_location {location; error = message}
2222+ `With_full_location {location; message}
23232424-let makef = fun format ->
2424+let filename_only : string -> string -> t = fun message file ->
2525+ `With_filename_only {file; message}
2626+2727+let format = fun format ->
2528 (Printf.ksprintf make) format
26292730let to_string : t -> string = function
2828- | `With_full_location {location; error} ->
3131+ | `With_full_location {location; message} ->
2932 let location_string =
3033 if location.start.line = location.end_.line then
3134 Printf.sprintf "line %i, characters %i-%i"
···3942 location.end_.line
4043 location.end_.column
4144 in
4242- Printf.sprintf "File \"%s\", %s:\n%s" location.file location_string error
4545+ Printf.sprintf "File \"%s\", %s:\n%s" location.file location_string message
43464444- | `With_filename_only {file; error} ->
4545- Printf.sprintf "File \"%s\":\n%s" file error
4747+ | `With_filename_only {file; message} ->
4848+ Printf.sprintf "File \"%s\":\n%s" file message
46494750exception Conveyed_by_exception of t
4851
+12-6
src/parser/parse_error.ml
···445566let bad_markup : string -> Location.span -> Error.t =
77- Error.makef "'%s': bad markup"
77+ Error.format "'%s': bad markup"
8899let bad_section_level : string -> Location.span -> Error.t =
1010- Error.makef "'%s': bad section level (2-4 allowed)"
1010+ Error.format "'%s': bad section level (2-4 allowed)"
11111212let cannot_be_empty : what:string -> Location.span -> Error.t = fun ~what ->
1313- Error.makef "%s cannot be empty" what
1313+ Error.format "%s cannot be empty" what
14141515let must_begin_on_its_own_line : what:string -> Location.span -> Error.t =
1616 fun ~what ->
1717- Error.makef "%s must begin on its own line" what
1717+ Error.format "%s must begin on its own line" what
18181919let must_be_followed_by_whitespace : what:string -> Location.span -> Error.t =
2020 fun ~what ->
2121- Error.makef "%s must be followed by space, a tab, or a new line" what
2121+ Error.format "%s must be followed by space, a tab, or a new line" what
22222323let not_allowed
2424 : ?suggestion:string -> what:string -> in_what:string -> Location.span ->
···3838let no_trailing_whitespace_in_verbatim : Location.span -> Error.t =
3939 Error.make "'v}' must be preceded by whitespace"
40404141+let only_one_title_allowed : Location.span -> Error.t =
4242+ Error.make "only one title-level heading is allowed"
4343+4444+let sections_not_allowed : Location.span -> Error.t =
4545+ Error.make "sections not allowed in this comment"
4646+4147let stray_at : Location.span -> Error.t =
4248 Error.make "stray '@'"
4349···5763 Error.make "'@see' must be followed by <url>, 'file', or \"document title\""
58645965let unknown_tag : string -> Location.span -> Error.t =
6060- Error.makef "unknown tag '%s'"
6666+ Error.format "unknown tag '%s'"
61676268let unpaired_right_brace : Location.span -> Error.t =
6369 Error.make "unpaired '}' (end of markup)"
+5-24
src/parser/semantics.ml
···34343535 match status.sections_allowed, level with
3636 | `None, _ ->
3737- let message : Error.t =
3838- `With_full_location {
3939- location;
4040- error = "sections not allowed in this comment";
4141- }
4242- in
4343- warning status message;
3737+ warning status (Parse_error.sections_not_allowed location);
4438 let element =
4539 Location.at location
4640 (`Paragraph [Location.at location
···4943 parsed_a_title, element
50445145 | `All, 1 ->
5252- if parsed_a_title then begin
5353- let message : Error.t =
5454- `With_full_location {
5555- location = location;
5656- error = "only one title-level heading is allowed";
5757- }
5858- in
5959- Error.raise_exception message
6060- end;
4646+ if parsed_a_title then
4747+ Error.raise_exception (Parse_error.only_one_title_allowed location);
6148 let element = `Heading (`Title, label, content) in
6249 let element = Location.at location element in
6350 true, element
···6956 | 3 -> `Subsection
7057 | 4 -> `Subsubsection
7158 | _ ->
7272- let message : Error.t =
7373- `With_full_location {
7474- location = location;
7575- error =
7676- Printf.sprintf "'%i': bad section level (2-4 allowed)" level;
7777- }
7878- in
7979- warning status message;
5959+ Parse_error.bad_section_level (string_of_int level) location
6060+ |> warning status;
8061 if level < 2 then
8162 `Section
8263 else