Protocol Buffers codec for hand-written schemas
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

WIP: dune build fixes — json/value.t, plain to_string, sw moves

+106
+46
lib/error.ml
··· 1 + type kind = Loc.Error.kind = .. 2 + 3 + type Loc.Error.kind += 4 + | Wire_type_mismatch of { expected : Wire.t; found : Wire.t } 5 + | Unterminated_varint 6 + | Varint_overflow 7 + | Depth_exceeded of int 8 + | Reserved_tag_zero 9 + | Unsupported_wire_type of int 10 + | Truncated of { need : int; have : int } 11 + | Overrun 12 + 13 + type t = Loc.Error.t 14 + 15 + let () = 16 + Loc.Error.register_kind_printer (function 17 + | Wire_type_mismatch { expected; found } -> 18 + Some 19 + (fun ppf -> 20 + Fmt.pf ppf "wire type mismatch: expected %a, got %a" Wire.pp 21 + expected Wire.pp found) 22 + | Unterminated_varint -> 23 + Some (fun ppf -> Fmt.string ppf "unterminated varint") 24 + | Varint_overflow -> Some (fun ppf -> Fmt.string ppf "varint overflow") 25 + | Depth_exceeded n -> 26 + Some (fun ppf -> Fmt.pf ppf "nested message depth %d exceeded" n) 27 + | Reserved_tag_zero -> 28 + Some (fun ppf -> Fmt.string ppf "tag: field number 0 is reserved") 29 + | Unsupported_wire_type n -> 30 + Some (fun ppf -> Fmt.pf ppf "unsupported wire type %d" n) 31 + | Truncated { need; have } -> 32 + Some 33 + (fun ppf -> Fmt.pf ppf "truncated: need %d bytes, have %d" need have) 34 + | Overrun -> Some (fun ppf -> Fmt.string ppf "overran message boundary") 35 + | _ -> None) 36 + 37 + let pp = Loc.Error.pp 38 + let to_string = Loc.Error.to_string 39 + let raise_kind k = Loc.Error.raise ~ctx:Loc.Context.empty ~meta:Loc.Meta.none k 40 + let raisef fmt = Fmt.kstr (fun s -> Loc.Error.fail Loc.Meta.none s) fmt 41 + 42 + (* Legacy bridge: wire.ml still raises [Wire.Decode_error of string] 43 + from within varint/scalar readers. [of_wire_error] converts it to a 44 + [Loc.Error.t] with kind [Loc.Error.Msg]. *) 45 + let of_wire_error msg = 46 + Loc.Error.msg ~ctx:Loc.Context.empty ~meta:Loc.Meta.none msg
+60
lib/error.mli
··· 1 + (** Protobuf-specific error helpers. 2 + 3 + Extends {!Loc.Error.kind} with the distinct protobuf wire-format failures so 4 + callers can pattern-match on them instead of parsing error strings. The main 5 + type is a plain alias for {!Loc.Error.t}; all the standard [ctx] / [meta] / 6 + [pp] / [to_string] machinery applies. *) 7 + 8 + type kind = Loc.Error.kind = .. 9 + (** Alias for {!Loc.Error.kind} so the protobuf-specific constructors appear in 10 + the same type. *) 11 + 12 + type Loc.Error.kind += 13 + | Wire_type_mismatch of { expected : Wire.t; found : Wire.t } 14 + (** The schema declares a different wire type than the wire carries — 15 + e.g. [int32 a = 1] (varint) but the wire has a length-delimited 16 + value at tag 1. *) 17 + | Unterminated_varint 18 + (** A varint byte stream ended without a terminator byte. *) 19 + | Varint_overflow 20 + (** A varint had more than 10 bytes or the 10th byte's payload exceeds 21 + the 64-bit range. *) 22 + | Depth_exceeded of int 23 + (** Nested-message decoding exceeded the depth limit (argument is the 24 + limit). *) 25 + | Reserved_tag_zero 26 + (** The wire carried a tag with field number 0, which is reserved by the 27 + protobuf spec. *) 28 + | Unsupported_wire_type of int 29 + (** The wire tag had a wire-type field other than 0/1/2/5 (i.e. a 30 + deprecated group, 3 or 4, or an invalid value). *) 31 + | Truncated of { need : int; have : int } 32 + (** Decoder needed [need] bytes but only [have] remained. *) 33 + | Overrun 34 + (** The decoder finished a field past the declared message boundary — a 35 + length-prefix lied about how many bytes follow. *) 36 + 37 + type t = Loc.Error.t 38 + (** Alias for {!Loc.Error.t}. *) 39 + 40 + val pp : t Fmt.t 41 + (** [pp ppf e] formats the error using {!Loc.Error.pp}. *) 42 + 43 + val to_string : t -> string 44 + (** [to_string e] is {!pp} applied to a fresh buffer. *) 45 + 46 + (** {1 Raising helpers} *) 47 + 48 + val raise_kind : kind -> 'a 49 + (** [raise_kind k] raises {!Loc.Error.Error} with an empty context and no meta. 50 + Used by the wire decoder where byte offsets aren't tracked yet. *) 51 + 52 + val raisef : ('a, Format.formatter, unit, 'b) format4 -> 'a 53 + (** [raisef fmt ...] is a convenience that raises a {!Loc.Error.Msg} with the 54 + formatted string. Matches {!Loc.Error.failf}. *) 55 + 56 + val of_wire_error : string -> t 57 + (** [of_wire_error msg] wraps a legacy {!Wire.Decode_error} string as a 58 + structured [Loc.Error.t] with an empty context and no meta. Used by the 59 + codec top-level to bridge the wire layer's exception into the public result 60 + type. *)