{"record":{"id":"c2d07a68b3c86af6","repo":"microsoft/typescript-go","slug":"invalid-s-got-v","errorCode":null,"errorMessage":"invalid %s: got %v","messagePattern":"invalid (.+?): got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lsp/lsproto/lsp.go","lineNumber":100,"sourceCode":"\ntype URI string // !!!\n\ntype Method string\n\nfunc errNotObject(k json.Kind) error {\n\treturn fmt.Errorf(\"expected object start, but encountered %v\", k)\n}\n\nfunc errNull(field string) error {\n\treturn fmt.Errorf(\"null value is not allowed for field %q\", field)\n}\n\nfunc errMissing(props []string) error {\n\treturn fmt.Errorf(\"missing required properties: %s\", strings.Join(props, \", \"))\n}\n\nfunc errInvalidKind(typeName string, got json.Kind) error {\n\treturn fmt.Errorf(\"invalid %s: got %v\", typeName, got)\n}\n\nfunc errInvalidValue(typeName string, data []byte) error {\n\treturn fmt.Errorf(\"invalid %s: %s\", typeName, data)\n}\n\nfunc errLiteralMismatch(typeName string, expected string, got []byte) error {\n\treturn fmt.Errorf(\"expected %s value %s, got %s\", typeName, expected, got)\n}\n\nfunc assertOnlyOne(message string, count int) {\n\tif count != 1 {\n\t\tpanic(message)\n\t}\n}\n\nfunc assertAtMostOne(message string, count int) {\n\tif count > 1 {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/lsp/lsproto/lsp.go#L82-L118","documentation":"Thrown when a value must decode into one of the generated union/alias types (e.g. IntegerOrString, StringOrMarkupContent, BooleanOrHoverOptions, the many XxxOrNull wrappers) but the JSON kind at the current position matches none of the union members. The generated decoders call errInvalidKind(typeName, dec.PeekKind()) after exhausting every case, so the message names the protocol type and the offending JSON kind.","triggerScenarios":"Sending a scalar where a union requires object/array, e.g. hover result as a bare string when only StringOrMarkupContent shapes are allowed, marking capabilities as true/false where the struct requires an object, null for XxxOrNull types whose null branch is only taken under exact kind matching, or an array where DocumentSelectorOrNull expects an object. Any params or result payload whose JSON kind does not satisfy the union's kind dispatch in lsp_generated.go.","commonSituations":"Clients implementing an older/newer LSP spec where a capability was boolean instead of object (or vice versa); hand-crafted JSON-RPC responses in tests; proxies that coerce types; sending null where the generated OrNull union still rejects it because the base type was not nullable in the meta model.","solutions":["Check the type name in the message against the LSP metaModel and reshape the JSON to one of the permitted shapes (e.g. replace `true` with an options object, or a string with {kind, value} markup content).","If the value can legitimately be absent, send null only if the type name ends in OrNull; otherwise omit the field entirely.","In tests, build the value by marshaling the corresponding generated Go union struct so only valid shapes are produced.","Regenerate lsproto from an updated meta model if the client legitimately sends a shape the current generated code predates."],"exampleFix":"// before: boolean where object union is required\n\"hoverProvider\": true\n// after (when the generated type demands options)\n\"hoverProvider\": {}","handlingStrategy":"type-guard","validationCode":"// before sending a capability value, confirm its JSON kind matches the union\nfunc kindOK(v any, allow ...string) bool {\n    kind := reflect.KindOf(v) // map[string]any -> \"object\", []any -> \"array\", etc.\n    return slices.Contains(allow, kind)\n}\n\n// e.g. DocumentSelectorOrNull takes array-or-null\nif v != nil && !kindOK(v, \"array\") { return fmt.Errorf(\"bad selector\") }","typeGuard":"func isObjectOrArray(v any) bool {\n    switch v.(type) {\n    case map[string]any, []any:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Consult the type name in the error against the LSP meta model before choosing a JSON shape.","Never send booleans/scalars where the spec declares an options object union.","Round-trip test payloads through the generated Go types."],"tags":["lsp","json","validation","protocol"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}