···11+type kind = Loc.Error.kind = ..
22+33+type Loc.Error.kind +=
44+ | Wire_type_mismatch of { expected : Wire.t; found : Wire.t }
55+ | Unterminated_varint
66+ | Varint_overflow
77+ | Depth_exceeded of int
88+ | Reserved_tag_zero
99+ | Unsupported_wire_type of int
1010+ | Truncated of { need : int; have : int }
1111+ | Overrun
1212+1313+type t = Loc.Error.t
1414+1515+let () =
1616+ Loc.Error.register_kind_printer (function
1717+ | Wire_type_mismatch { expected; found } ->
1818+ Some
1919+ (fun ppf ->
2020+ Fmt.pf ppf "wire type mismatch: expected %a, got %a" Wire.pp
2121+ expected Wire.pp found)
2222+ | Unterminated_varint ->
2323+ Some (fun ppf -> Fmt.string ppf "unterminated varint")
2424+ | Varint_overflow -> Some (fun ppf -> Fmt.string ppf "varint overflow")
2525+ | Depth_exceeded n ->
2626+ Some (fun ppf -> Fmt.pf ppf "nested message depth %d exceeded" n)
2727+ | Reserved_tag_zero ->
2828+ Some (fun ppf -> Fmt.string ppf "tag: field number 0 is reserved")
2929+ | Unsupported_wire_type n ->
3030+ Some (fun ppf -> Fmt.pf ppf "unsupported wire type %d" n)
3131+ | Truncated { need; have } ->
3232+ Some
3333+ (fun ppf -> Fmt.pf ppf "truncated: need %d bytes, have %d" need have)
3434+ | Overrun -> Some (fun ppf -> Fmt.string ppf "overran message boundary")
3535+ | _ -> None)
3636+3737+let pp = Loc.Error.pp
3838+let to_string = Loc.Error.to_string
3939+let raise_kind k = Loc.Error.raise ~ctx:Loc.Context.empty ~meta:Loc.Meta.none k
4040+let raisef fmt = Fmt.kstr (fun s -> Loc.Error.fail Loc.Meta.none s) fmt
4141+4242+(* Legacy bridge: wire.ml still raises [Wire.Decode_error of string]
4343+ from within varint/scalar readers. [of_wire_error] converts it to a
4444+ [Loc.Error.t] with kind [Loc.Error.Msg]. *)
4545+let of_wire_error msg =
4646+ Loc.Error.msg ~ctx:Loc.Context.empty ~meta:Loc.Meta.none msg
+60
lib/error.mli
···11+(** Protobuf-specific error helpers.
22+33+ Extends {!Loc.Error.kind} with the distinct protobuf wire-format failures so
44+ callers can pattern-match on them instead of parsing error strings. The main
55+ type is a plain alias for {!Loc.Error.t}; all the standard [ctx] / [meta] /
66+ [pp] / [to_string] machinery applies. *)
77+88+type kind = Loc.Error.kind = ..
99+(** Alias for {!Loc.Error.kind} so the protobuf-specific constructors appear in
1010+ the same type. *)
1111+1212+type Loc.Error.kind +=
1313+ | Wire_type_mismatch of { expected : Wire.t; found : Wire.t }
1414+ (** The schema declares a different wire type than the wire carries —
1515+ e.g. [int32 a = 1] (varint) but the wire has a length-delimited
1616+ value at tag 1. *)
1717+ | Unterminated_varint
1818+ (** A varint byte stream ended without a terminator byte. *)
1919+ | Varint_overflow
2020+ (** A varint had more than 10 bytes or the 10th byte's payload exceeds
2121+ the 64-bit range. *)
2222+ | Depth_exceeded of int
2323+ (** Nested-message decoding exceeded the depth limit (argument is the
2424+ limit). *)
2525+ | Reserved_tag_zero
2626+ (** The wire carried a tag with field number 0, which is reserved by the
2727+ protobuf spec. *)
2828+ | Unsupported_wire_type of int
2929+ (** The wire tag had a wire-type field other than 0/1/2/5 (i.e. a
3030+ deprecated group, 3 or 4, or an invalid value). *)
3131+ | Truncated of { need : int; have : int }
3232+ (** Decoder needed [need] bytes but only [have] remained. *)
3333+ | Overrun
3434+ (** The decoder finished a field past the declared message boundary — a
3535+ length-prefix lied about how many bytes follow. *)
3636+3737+type t = Loc.Error.t
3838+(** Alias for {!Loc.Error.t}. *)
3939+4040+val pp : t Fmt.t
4141+(** [pp ppf e] formats the error using {!Loc.Error.pp}. *)
4242+4343+val to_string : t -> string
4444+(** [to_string e] is {!pp} applied to a fresh buffer. *)
4545+4646+(** {1 Raising helpers} *)
4747+4848+val raise_kind : kind -> 'a
4949+(** [raise_kind k] raises {!Loc.Error.Error} with an empty context and no meta.
5050+ Used by the wire decoder where byte offsets aren't tracked yet. *)
5151+5252+val raisef : ('a, Format.formatter, unit, 'b) format4 -> 'a
5353+(** [raisef fmt ...] is a convenience that raises a {!Loc.Error.Msg} with the
5454+ formatted string. Matches {!Loc.Error.failf}. *)
5555+5656+val of_wire_error : string -> t
5757+(** [of_wire_error msg] wraps a legacy {!Wire.Decode_error} string as a
5858+ structured [Loc.Error.t] with an empty context and no meta. Used by the
5959+ codec top-level to bridge the wire layer's exception into the public result
6060+ type. *)