{"record":{"id":"80b68c72e9d62e4b","repo":"geektutu/7days-golang","slug":"rpc-server-can-t-find-method-80b68c","errorCode":null,"errorMessage":"rpc server: can't find method ","messagePattern":"rpc server: can't find method ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-rpc/day5-http-debug/server.go","lineNumber":128,"sourceCode":"\treturn &h, nil\n}\n\nfunc (server *Server) findService(serviceMethod string) (svc *service, mtype *methodType, err error) {\n\tdot := strings.LastIndex(serviceMethod, \".\")\n\tif dot < 0 {\n\t\terr = errors.New(\"rpc server: service/method request ill-formed: \" + serviceMethod)\n\t\treturn\n\t}\n\tserviceName, methodName := serviceMethod[:dot], serviceMethod[dot+1:]\n\tsvci, ok := server.serviceMap.Load(serviceName)\n\tif !ok {\n\t\terr = errors.New(\"rpc server: can't find service \" + serviceName)\n\t\treturn\n\t}\n\tsvc = svci.(*service)\n\tmtype = svc.method[methodName]\n\tif mtype == nil {\n\t\terr = errors.New(\"rpc server: can't find method \" + methodName)\n\t}\n\treturn\n}\n\nfunc (server *Server) readRequest(cc codec.Codec) (*request, error) {\n\th, err := server.readRequestHeader(cc)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treq := &request{h: h}\n\treq.svc, req.mtype, err = server.findService(h.ServiceMethod)\n\tif err != nil {\n\t\treturn req, err\n\t}\n\treq.argv = req.mtype.newArgv()\n\treq.replyv = req.mtype.newReplyv()\n\n\t// make sure that argvi is a pointer, ReadBody need a pointer as parameter","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-rpc/day5-http-debug/server.go#L110-L146","documentation":"The service was found in serviceMap, but the method part of \"Service.Method\" has no entry in svc.method. Methods are only registered if they are exported and match the required signature (two args, second a pointer, one error return), so a missing or non-conforming method yields this error.","triggerScenarios":"Call(\"Foo.Bar\") where Foo is registered but Bar does not exist, Bar is unexported (lowercase), or Bar exists but fails the signature check during registration and was therefore never added to the method table.","commonSituations":"Typos in the method name, renaming a method after registration, calling a method that is exported in one version but not another, or a method with the wrong signature (e.g. value second arg or no error return) that Register silently skipped.","solutions":["Fix the method name string to match the exported method exactly (case-sensitive)","Make the method exported and give it the signature func (t *T) M(args ArgsType, reply *ReplyType) error so Register publishes it","Check server logs at startup — Register skips non-conforming methods; also ensure Register's returned error is not ignored"],"exampleFix":"// before\nfunc (s *DemoService) div(args Args, reply *int) error { ... } // unexported, never registered\n// after\nfunc (s *DemoService) Div(args Args, reply *int) error { ... } // exported, matches required signature","handlingStrategy":"validation","validationCode":"// at startup, verify method registration succeeded\nif err := srv.Register(new(DemoService)); err != nil {\n    log.Fatalf(\"register DemoService failed: %v\", err)\n}\n// plus a startup self-check\nfunc assertMethods(svc string, methods ...string) {\n    for _, m := range methods {\n        if !hasExportedMethod(new(DemoService), m) {\n            log.Fatalf(\"%s.%s is missing or not exported\", svc, m)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"err := client.Call(\"DemoService.Div\", args, reply)\nif err != nil && strings.Contains(err.Error(), \"can't find method\") {\n    return fmt.Errorf(\"method Div is not registered (check export and signature: func (t *T) M(args A, reply *R) error): %w\", err)\n}","preventionTips":["Export all RPC methods (capitalized names) and use the canonical signature (two args, pointer reply, error return)","Never ignore the error returned by Register — it lists services that failed to publish","Add reflection-based startup checks that every method the client will call exists on the receiver","Run a contract test that calls every registered method name once"],"tags":["rpc","method-lookup","reflection"],"backgroundTag":"rpc-method-not-found","analyzedSha":"cf3644382101dc13e7fd92e8f5c66cabc51bcd3b","analyzedAt":"2026-09-03T18:31:24.087Z","contentChangedAt":"2026-09-03T18:31:24.087Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}