{"record":{"id":"b42f5276e76a1cbb","repo":"microsoft/typescript-go","slug":"invalid-s-s","errorCode":null,"errorMessage":"invalid %s: %s","messagePattern":"invalid (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lsp/lsproto/lsp.go","lineNumber":104,"sourceCode":"\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 {\n\t\tpanic(message)\n\t}\n}\n","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/lsp/lsproto/lsp.go#L86-L122","documentation":"The last-resort decode failure for polymorphic LSP types: after kind-based dispatch narrows the candidate members of a union (e.g. TextEditOrInsertReplaceEdit, WorkspaceFullDocumentDiagnosticReportOrUnchangedDocumentDiagnosticReport, WorkDoneProgressBeginOrReportOrEnd), each candidate is trial-unmarshaled; if all fail, errInvalidValue(typeName, data) reports the type name plus the raw JSON bytes. Unlike errInvalidKind this means the JSON kind was plausible but the contents did not satisfy any member.","triggerScenarios":"A diagnostic report lacking its required kind discriminator; a TextEdit whose range is absent or malformed; a progress value whose kind is neither begin, report, nor end; a WorkspaceEdit with an unknown structure. Any payload that passes the kind check but fails every candidate's field validation in lsp_generated.go (errMissing/errNull inside trial unmarshals bubble up to this catch-all).","commonSituations":"Clients that omit discriminator fields like kind; stale code assuming a rename result shape from an older LSP version; AI-generated or hand-written JSON fixtures; middleware that drops nested required fields while transforming payloads.","solutions":["Inspect the raw JSON echoed in the error and compare it against the member shapes of the named union in the LSP spec; fix the missing/invalid nested field (usually a missing `kind` or `range`).","Add the discriminator the union dispatches on (e.g. \"kind\":\"begin\" for progress, \"kind\":\"full\" for diagnostic reports).","Validate outbound payloads in tests by unmarshaling into the generated lsproto union type before sending."],"exampleFix":"// before: diagnostic report without discriminator\n{\"resultId\":\"1\",\"items\":[]}\n// after\n{\"kind\":\"full\",\"resultId\":\"1\",\"items\":[]}","handlingStrategy":"validation","validationCode":"// ensure discriminator-bearing unions carry a known `kind`\nvar knownKinds = map[string]bool{\"full\": true, \"unchanged\": true}\n\nfunc validReport(r map[string]any) bool {\n    k, _ := r[\"kind\"].(string)\n    return knownKinds[k]\n}","typeGuard":"func hasKnownDiscriminator(v map[string]any, key string, allowed map[string]bool) bool {\n    s, ok := v[key].(string)\n    return ok && allowed[s]\n}","tryCatchPattern":null,"preventionTips":["Always emit the `kind` discriminator on polymorphic LSP values (reports, progress, edits).","Validate nested payloads against the generated union types in tests before shipping fixtures.","Use the lsproto Go types to construct values so invalid members cannot be expressed."],"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"}