Skip to content

Commit a220087

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
internal/lsp/protocol: ignore reply values with non-nil errors in jsonrpc2_v2 adapters
The documentation for jsonrpc2.Replier states that “[i]f err is set then result will be ignored.” jsonrpc2_v2 documents no such affordance, and the JSON-RPC 2.0 protocol explicitly requires that the result “MUST NOT exist if there was an error invoking the method.” Although CL 388600 already avoids returning values in case of error (which may also help with escape analysis and/or allocation efficiency), it seems simplest and least confusing to make the semantic difference between the jsonrpc2.Handler and jsonrpc2_v2.Handler explicit in the code. For golang/go#46520. Change-Id: If13eb842505d42cbc51c01f5f5e699a549a3a28b Reviewed-on: https://go-review.googlesource.com/c/tools/+/400054 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent d5f48fc commit a220087

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/lsp/protocol/protocol.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ func ClientHandlerV2(client Client) jsonrpc2_v2.Handler {
134134
resErr error
135135
)
136136
replier := func(_ context.Context, res interface{}, err error) error {
137-
result, resErr = res, err
137+
if err != nil {
138+
resErr = err
139+
return nil
140+
}
141+
result = res
138142
return nil
139143
}
140144
_, err := clientDispatch(ctx, client, replier, req1)
@@ -179,7 +183,11 @@ func ServerHandlerV2(server Server) jsonrpc2_v2.Handler {
179183
resErr error
180184
)
181185
replier := func(_ context.Context, res interface{}, err error) error {
182-
result, resErr = res, err
186+
if err != nil {
187+
resErr = err
188+
return nil
189+
}
190+
result = res
183191
return nil
184192
}
185193
_, err := serverDispatch(ctx, server, replier, req1)

0 commit comments

Comments
 (0)