···11+(** Error handling for the Claude protocol.
22+33+ This module provides a protocol-specific exception and Result combinators
44+ for handling JSON encoding/decoding errors in the Claude SDK. *)
55+66+exception Protocol_error of string
77+(** Raised when there is an error in the Claude protocol, such as JSON
88+ encoding/decoding failures or malformed messages. *)
99+1010+(** [protocol_error msg] raises [Protocol_error msg]. *)
1111+let protocol_error msg = raise (Protocol_error msg)
1212+1313+(** [get_ok ~msg r] returns [x] if [r] is [Ok x], or raises
1414+ [Protocol_error (msg ^ e)] if [r] is [Error e]. *)
1515+let get_ok ~msg = function
1616+ | Ok x -> x
1717+ | Error e -> raise (Protocol_error (msg ^ e))
1818+1919+(** [get_ok' ~msg r] returns [x] if [r] is [Ok x], or raises
2020+ [Invalid_argument (msg ^ e)] if [r] is [Error e]. Use this for user-facing
2121+ parse errors where Invalid_argument is expected. *)
2222+let get_ok' ~msg = function
2323+ | Ok x -> x
2424+ | Error e -> raise (Invalid_argument (msg ^ e))
+20
lib/err.mli
···11+(** Error handling for the Claude protocol.
22+33+ This module provides a protocol-specific exception and Result combinators
44+ for handling JSON encoding/decoding errors in the Claude SDK. *)
55+66+exception Protocol_error of string
77+(** Raised when there is an error in the Claude protocol, such as JSON
88+ encoding/decoding failures or malformed messages. *)
99+1010+val protocol_error : string -> 'a
1111+(** [protocol_error msg] raises [Protocol_error msg]. *)
1212+1313+val get_ok : msg:string -> ('a, string) result -> 'a
1414+(** [get_ok ~msg r] returns [x] if [r] is [Ok x], or raises
1515+ [Protocol_error (msg ^ e)] if [r] is [Error e]. *)
1616+1717+val get_ok' : msg:string -> ('a, string) result -> 'a
1818+(** [get_ok' ~msg r] returns [x] if [r] is [Ok x], or raises
1919+ [Invalid_argument (msg ^ e)] if [r] is [Error e]. Use this for user-facing
2020+ parse errors where Invalid_argument is expected. *)