Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: tolerate JSON decoding failures from type mismatch if the affected field is unused #45316

Closed
hyangah opened this issue Mar 31, 2021 · 4 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Mar 31, 2021

During VSCode v0.23.1 release that included backward-incompatible change (upgrading LSP 3.16 prerelease to stable), we encountered an error like

Starting client failed
  Message: JSON RPC parse error: json: cannot unmarshal number into Go struct field RenameClientCapabilities.capabilities.textDocument.rename.prepareSupportDefaultBehavior of type bool: JSON RPC parse error
  Code: -32700 

that stopped gopls. (golang/vscode-go#1328)

The problematic field prepareSupportDefaultBehavior is not used by gopls in this specific case. Please investigate if gopls can handle this kind of type mismatch gracefully (i.e. decoding only necessary, relevant fields) for improved forward compatibility.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 31, 2021
@gopherbot gopherbot added this to the Unreleased milestone Mar 31, 2021
@pjweinb
Copy link

pjweinb commented Apr 5, 2021

I propose closing this issue. Fixing it would appear to require figuring out which fields in which LSP protocol messages gopls doesn't use (and won't use). I see no reasonable way of doing that, other than by hand. (If we knew which fields these were, then we could either just leave them out of the generated tsprotocol.go, or write special code in place of json.Unmarshal.)

@stamblerre
Copy link
Contributor

We've discussed this issue and decided that it makes sense to pursue this.

One option is to compile a list of the fields that we use in the initialization options and only add those fields to the struct in the LSP API generator. If a new field gets used in a future version, we will have to manually add it to the list of used fields.

@heschi and @ianthehat also suggested the possibility of checking the error message to get the name of the unknown field, unmarshaling the message to a map[string]interface{}, deleting the problematic field, and then trying to unmarshal to a struct again, until there are no errors. If that is feasible, that seems like it may be a better approach.

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Apr 6, 2021
@pjweinb
Copy link

pjweinb commented Apr 11, 2021

The simplest way to handle this error is to keep going if the error is an *json.UnmarshalType error. Tests show that the unmarshalled struct has all its other fields filled in properly. Probably the error should be logged.

@pjweinb
Copy link

pjweinb commented Apr 30, 2021

fixed by https://go-review.googlesource.com/c/tools/+/310753
(the CL for that refers to the wrong issue)

@pjweinb pjweinb closed this as completed Apr 30, 2021
gopls on-deck automation moved this from To Do to Done Apr 30, 2021
@golang golang locked and limited conversation to collaborators Apr 30, 2022
@rsc rsc unassigned pjweinb Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
No open projects
Development

No branches or pull requests

4 participants