{"record":{"id":"3a996277fcbfb8b8","repo":"microsoft/typescript-go","slug":"failed-to-unmarshal-t-w","errorCode":null,"errorMessage":"failed to unmarshal %T: %w","messagePattern":"failed to unmarshal %T: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/api/proto.go","lineNumber":1462,"sourceCode":"\tresult := make([]*DiagnosticResponse, len(diags))\n\tfor i, d := range diags {\n\t\tresult[i] = NewDiagnosticResponse(d)\n\t}\n\treturn result\n}\n\nfunc unmarshalPayload(method string, payload json.Value) (any, error) {\n\tunmarshaler, ok := unmarshalers[Method(method)]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unknown API method %q\", method)\n\t}\n\treturn unmarshaler(payload)\n}\n\nfunc unmarshallerFor[T any](data []byte) (any, error) {\n\tvar v T\n\tif err := json.Unmarshal(data, &v); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal %T: %w\", (*T)(nil), err)\n\t}\n\treturn &v, nil\n}\n\nfunc noParams(data []byte) (any, error) {\n\treturn nil, nil\n}\n","sourceCodeStart":1444,"sourceCodeEnd":1470,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/api/proto.go#L1444-L1470","documentation":"The request's params JSON failed to unmarshal into the strongly-typed params struct registered for that method (unmarshallerFor[T]). The message prints the Go type name and the underlying json error, which names the offending field and reason.","triggerScenarios":"Wrong field types (string where a number is expected), missing required fields, extra nesting levels, malformed values inside nested structures.","commonSituations":"Schema drift between client models and server structs after an upgrade; hand-written JSON; numeric fields sent as quoted strings; enum fields with unknown values.","solutions":["Match the client's types to the server's params struct for that method in proto.go","Validate the payload against the expected shape before sending","Fix the specific field named in the wrapped json error","Add contract tests that round-trip params through JSON"],"exampleFix":"// before\n{ \"file\": \"/a.ts\", \"line\": \"7\" } // line as string\n\n// after\n{ \"file\": \"/a.ts\", \"line\": 7 }","handlingStrategy":"validation","validationCode":"// Prove the payload marshals into the expected shape before sending.\nif _, err := json.Marshal(params); err != nil {\n\treturn fmt.Errorf(\"params not serializable: %w\", err)\n}\n// During development, round-trip against the server's params type:\nvar want api.GetDiagnosticsParams\nif b, _ := json.Marshal(params); json.Unmarshal(b, &want) != nil {\n\treturn errors.New(\"params do not match server schema\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate client types from the server's proto.go structs","Contract-test params round-trip through JSON on both sides","Fix fields exactly as the wrapped json error names them"],"tags":["go","json","unmarshal","params","schema","type-mismatch"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}