1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00

warn when marshaling invalid Response

This commit is contained in:
Quinn Slack 2017-01-22 15:45:18 -08:00
parent 9edf388fe1
commit a61d8f7bd7

View file

@ -132,6 +132,9 @@ func (r *Response) MarshalJSON() ([]byte, error) {
if r == nil {
return nil, errors.New("can't marshal nil *jsonrpc2.Response")
}
if (r.Result == nil || len(*r.Result) == 0) && r.Error == nil {
return nil, errors.New("can't marshal *jsonrpc2.Response (must have result or error)")
}
b, err := json.Marshal(*r)
if err != nil {
return nil, err