···1+(** Error handling for the Claude protocol.
2+3+ This module provides a protocol-specific exception and Result combinators
4+ for handling JSON encoding/decoding errors in the Claude SDK. *)
5+6+exception Protocol_error of string
7+(** Raised when there is an error in the Claude protocol, such as JSON
8+ encoding/decoding failures or malformed messages. *)
9+10+(** [protocol_error msg] raises [Protocol_error msg]. *)
11+let protocol_error msg = raise (Protocol_error msg)
12+13+(** [get_ok ~msg r] returns [x] if [r] is [Ok x], or raises
14+ [Protocol_error (msg ^ e)] if [r] is [Error e]. *)
15+let get_ok ~msg = function
16+ | Ok x -> x
17+ | Error e -> raise (Protocol_error (msg ^ e))
18+19+(** [get_ok' ~msg r] returns [x] if [r] is [Ok x], or raises
20+ [Invalid_argument (msg ^ e)] if [r] is [Error e]. Use this for user-facing
21+ parse errors where Invalid_argument is expected. *)
22+let get_ok' ~msg = function
23+ | Ok x -> x
24+ | Error e -> raise (Invalid_argument (msg ^ e))
+20
lib/err.mli
···00000000000000000000
···1+(** Error handling for the Claude protocol.
2+3+ This module provides a protocol-specific exception and Result combinators
4+ for handling JSON encoding/decoding errors in the Claude SDK. *)
5+6+exception Protocol_error of string
7+(** Raised when there is an error in the Claude protocol, such as JSON
8+ encoding/decoding failures or malformed messages. *)
9+10+val protocol_error : string -> 'a
11+(** [protocol_error msg] raises [Protocol_error msg]. *)
12+13+val get_ok : msg:string -> ('a, string) result -> 'a
14+(** [get_ok ~msg r] returns [x] if [r] is [Ok x], or raises
15+ [Protocol_error (msg ^ e)] if [r] is [Error e]. *)
16+17+val get_ok' : msg:string -> ('a, string) result -> 'a
18+(** [get_ok' ~msg r] returns [x] if [r] is [Ok x], or raises
19+ [Invalid_argument (msg ^ e)] if [r] is [Error e]. Use this for user-facing
20+ parse errors where Invalid_argument is expected. *)