Skip to content

Commit

Permalink
Better-document guaranteed successes.
Browse files Browse the repository at this point in the history
Unmarshaling Request parameters and Response results will always
succeed if there is a value to decode and the output type is a
json.RawMessage. Document that this special case is intentional.
  • Loading branch information
creachadair committed Sep 12, 2021
1 parent a746f74 commit da0026c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (r *Request) HasParams() bool { return len(r.params) != 0 }
// method. The jrpc2.StrictFields helper function adapts existing values to
// this interface.
//
// If v has type *json.RawMessage, decoding cannot fail.
// If r has parameters and v has type *json.RawMessage, unmarshaling will
// always succeed.
func (r *Request) UnmarshalParams(v interface{}) error {
if len(r.params) == 0 {
return nil
Expand Down Expand Up @@ -159,6 +160,9 @@ func (r *Response) Error() *Error { return r.err }
// implementation of json.Unmarshaler, or implementing a DisallowUnknownFields
// method. The jrpc2.StrictFields helper function adapts existing values to
// this interface.
//
// If r has a result and v has type *json.RawMessage, unmarshaling will always
// succeed.
func (r *Response) UnmarshalResult(v interface{}) error {
if r.err != nil {
return r.err
Expand Down

0 comments on commit da0026c

Please sign in to comment.