{"record":{"id":"252c05e03b68c101","repo":"microsoft/typescript-go","slug":"api-remote-error-d-s","errorCode":null,"errorMessage":"api: remote error [%d]: %s","messagePattern":"api: remote error \\[(.+?)\\]: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/api/conn_async.go","lineNumber":220,"sourceCode":"\t\t\tdelete(c.pending, *id)\n\t\t}\n\t}()\n\n\t// Send the request\n\tc.writeMu.Lock()\n\terr := c.protocol.WriteRequest(id, method, params)\n\tc.writeMu.Unlock()\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tselect {\n\tcase <-ctx.Done():\n\t\treturn nil, ctx.Err()\n\tcase resp := <-responseChan:\n\t\tif resp.Error != nil {\n\t\t\treturn nil, fmt.Errorf(\"api: remote error [%d]: %s\", resp.Error.Code, resp.Error.Message)\n\t\t}\n\t\treturn resp.Result, nil\n\t}\n}\n\n// Notify sends a notification to the client (no response expected).\nfunc (c *AsyncConn) Notify(ctx context.Context, method string, params any) error {\n\tc.writeMu.Lock()\n\tdefer c.writeMu.Unlock()\n\treturn c.protocol.WriteNotification(method, params)\n}\n","sourceCodeStart":202,"sourceCodeEnd":232,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/api/conn_async.go#L202-L232","documentation":"AsyncConn.Call received a well-formed error response from the peer and wrapped it: the number is the JSON-RPC error code, the text the remote message. It is the generic surface for every server-returned error, not a distinct failure itself.","triggerScenarios":"Calling any method the server rejects: unknown method, invalid params (e.g. missing required field), server-side internal errors, or cancellation surfaced as an error.","commonSituations":"Method name typos or version skew between client and server; sending params not matching the server's expected shape; legitimate domain errors (file not found, invalid arguments) reported through JSON-RPC.","solutions":["Inspect the message text and code to identify the real cause — fix the request accordingly","Verify method names/params against the API surface of the matching server version","If the code indicates -32601/-32602, correct the method/params; for -32603 treat as server bug and update","Wrap Call results and surface err.Error() to logs for diagnosis"],"exampleFix":"// before\nresult, err := conn.Call(ctx, \"geterr\", args)\nif err != nil { panic(err) }\n\n// after\nresult, err := conn.Call(ctx, \"geterr\", args)\nif err != nil {\n    log.Printf(\"server rejected geterr: %v\", err)\n    return diagnose(err) // map message/code to a user-facing cause\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"result, err := conn.Call(ctx, method, params)\nif err != nil {\n    var re = regexp.MustCompile(`remote error \\[(\\-?\\d+)\\]: (.*)`)\n    if m := re.FindStringSubmatch(err.Error()); m != nil {\n        code, _ := strconv.Atoi(m[1]); msg := m[2]\n        switch code {\n        case -32601: // unknown method\n        case -32602: // bad params\n        default: // domain/internal error\n        }\n    }\n}","preventionTips":["Check method names/params against the server version actually deployed","Parse the code out of the message before deciding retry vs fail","Wrap every Call with structured logging of code+message"],"tags":["json-rpc","go","remote-error","api"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}