mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-19 05:30:03 +02:00
warn when marshaling invalid Response
This commit is contained in:
parent
9edf388fe1
commit
a61d8f7bd7
1 changed files with 3 additions and 0 deletions
|
|
@ -132,6 +132,9 @@ func (r *Response) MarshalJSON() ([]byte, error) {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return nil, errors.New("can't marshal nil *jsonrpc2.Response")
|
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)
|
b, err := json.Marshal(*r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue