{"record":{"id":"223b2e699fc413cd","repo":"go-kratos/kratos","slug":"errorcode-d","errorCode":null,"errorMessage":"ErrorCode: %d","messagePattern":"ErrorCode: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"contrib/registry/discovery/discovery.go","lineNumber":293,"sourceCode":"\t// send request to Discovery server.\n\tif _, err = d.httpClient.R().\n\t\tSetContext(context.Background()).\n\t\tSetQueryParamsFromValues(p).\n\t\tSetResult(&res).\n\t\tPost(uri); err != nil {\n\t\td.switchNode()\n\t\tlog.Error(\"Discovery: cancel client.Get failed\", \"uri\", uri, \"env\", config.Env, \"appid\", ins.AppID, \"hostname\", config.Host, \"error\", err)\n\t\treturn\n\t}\n\n\t// handle response error\n\tif res.Code != _codeOK {\n\t\tif res.Code == _codeNotFound {\n\t\t\treturn nil\n\t\t}\n\n\t\tlog.Warn(\"Discovery: cancel client.Get returned code\", \"uri\", uri, \"env\", config.Env, \"appid\", ins.AppID, \"hostname\", config.Host, \"code\", res.Code)\n\t\terr = fmt.Errorf(\"ErrorCode: %d\", res.Code)\n\t\treturn\n\t}\n\n\treturn\n}\n\nfunc (d *Discovery) broadcast(apps map[string]*disInstancesInfo) {\n\tfor appID, v := range apps {\n\t\tvar count int\n\t\t// v maybe nil in old version(less than v1.1) Discovery, check in case of panic\n\t\tif v == nil {\n\t\t\tcontinue\n\t\t}\n\t\tfor zone, ins := range v.Instances {\n\t\t\tif len(ins) == 0 {\n\t\t\t\tdelete(v.Instances, zone)\n\t\t\t}\n\t\t\tcount += len(ins)","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/contrib/registry/discovery/discovery.go#L275-L311","documentation":"Bilibili Discovery client: when cancelling a watch, the server answered with an application code that is neither OK nor NotFound, and the numeric code is wrapped as 'ErrorCode: %d'. The client logs a warning and switches to the next Discovery node, so this surfaces mainly as an error from cancel/close paths.","triggerScenarios":"Calling the Discovery client's Cancel path; the cancel request to the Discovery server returns res.Code != _codeOK and != _codeNotFound, so the code is wrapped into an error.","commonSituations":"Mismatched appid/env between client and server; permission/auth rejection of the cancel; Discovery server version skew; node switching mid-request.","solutions":["Verify appid/env/hostname config matches what the Discovery server expects","Check Discovery server logs to map the numeric code to its cause","Do not treat cancel/close failures as fatal on shutdown paths — the client already switched nodes","Align client and Discovery server versions if skew persists"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := disc.Close(); err != nil {\n    if strings.HasPrefix(err.Error(), \"ErrorCode:\") {\n        // server rejected the cancel; the client already switched nodes\n        log.Debug(\"discovery cancel rejected:\", err)\n        return nil\n    }\n    return err\n}","preventionTips":["Keep appid/env/hostname consistent with the Discovery server","Do not treat shutdown-path cancel errors as fatal","Track Discovery server release notes for behavior changes"],"tags":["discovery","bilibili","registry","network","shutdown"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}