Commits

Anonymous committed e48d0e8

Consolidate the exceptions into one [Error] exception with a variant type.

  • Participants
  • Parent commits e9b1700

Comments (0)

Files changed (2)

File mime/mime_lex.ml

 
 let crlf_string_ = "\r\n"
 
-exception Bad_field_name of int * Cf_message.t
+type error =
+    | X_field_bad_syntax of int * Cf_message.t
+    | X_field_duplicated of string
+
+exception Error of error
 
 let split_at_body =
     let rec loop pos z =
     else
     	match parse_field_name (Cf_message.to_seq field) with
     	| None ->
-    		raise (Bad_field_name (line, field))
+    		raise (Error (X_field_bad_syntax (line, field)))
     	| Some (name, z) ->
     		let acc = (line, name, z) :: acc in
     		split_into_fields_loop_ f (line + rows) acc m tl
     in
     fun m -> split_into_fields_and_map f m
 
-exception Field_duplicated
-
 let err_default_ _ = Cf_parser.Error
 
 let select_field ?(err = err_default_) name parse =
             match h1 with
             | [] ->
                 raise Not_found
-            | _ :: _ :: _ ->
-                raise Field_duplicated
+            | (name, _) :: _ :: _ ->
+                raise (Error (X_field_duplicated name))
             | (_, text) :: [] -> 
                 lazy begin
                     match parse text with
             match h1 with
             | [] ->
                 Lazy.lazy_from_val None
-            | _ :: _ :: _ ->
-                raise Field_duplicated
+            | (name, _) :: _ :: _ ->
+                raise (Error (X_field_duplicated name))
             | (_, text) :: [] -> 
                 lazy begin
                     match parse text with

File mime/mime_lex.mli

 
 (* Message splitting and field selecting *)
 
-exception Bad_field_name of int * Cf_message.t
+type error =
+    | X_field_bad_syntax of int * Cf_message.t
+    | X_field_duplicated of string
+
+exception Error of error
 
 val split_at_body: Cf_message.t -> Cf_message.t * Cf_message.t
 
     Cf_message.t ->
     (string * (char * Cf_lex.cursor) Cf_seq.t) list * Cf_message.t
 
-exception Field_duplicated
-
 val select_field:
     ?err:('i Cf_seq.t -> exn) -> string -> ('i, 'o) Cf_parser.t ->
     (string * 'i Cf_seq.t) list ->