{"record":{"id":"0bec7c7a96a7f12a","repo":"micro/go-micro","slug":"rpc-handle-handler-has-no-name","errorCode":null,"errorMessage":"rpc.Handle: handler has no name","messagePattern":"rpc\\.Handle: handler has no name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/rpc_router.go","lineNumber":461,"sourceCode":"\t}\n\n\treturn\n}\n\nfunc (router *router) NewHandler(h interface{}, opts ...HandlerOption) Handler {\n\treturn NewRpcHandler(h, opts...)\n}\n\nfunc (router *router) Handle(h Handler) error {\n\trouter.mu.Lock()\n\tdefer router.mu.Unlock()\n\n\tif router.serviceMap == nil {\n\t\trouter.serviceMap = make(map[string]*service)\n\t}\n\n\tif len(h.Name()) == 0 {\n\t\treturn errors.New(\"rpc.Handle: handler has no name\")\n\t}\n\n\tif !isExported(h.Name()) {\n\t\treturn errors.New(\"rpc.Handle: type \" + h.Name() + \" is not exported\")\n\t}\n\n\trcvr := h.Handler()\n\ts := new(service)\n\ts.typ = reflect.TypeOf(rcvr)\n\ts.rcvr = reflect.ValueOf(rcvr)\n\n\t// check name\n\tif _, present := router.serviceMap[h.Name()]; present {\n\t\treturn errors.New(\"rpc.Handle: service already defined: \" + h.Name())\n\t}\n\n\ts.name = h.Name()\n\ts.method = make(map[string]*methodType)","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/server/rpc_router.go#L443-L479","documentation":"Handle was called with a handler whose Name() returns an empty string. The router refuses to register a service with no name because it could never be addressed by an endpoint. This is a registration-time (startup) error, not a request-time error.","triggerScenarios":"Constructing a handler wrapper whose name field was never set (e.g. NewHandler with an empty name option), or a custom Handler implementation returning \"\" from Name().","commonSituations":"Passing an empty string to a name parameter/option; building handlers dynamically from config where the name key is missing; a custom Handler type forgetting to implement Name().","solutions":["Provide a non-empty name when constructing the handler (option or constructor argument)","Check the config/source of the handler name for missing or empty values","If implementing a custom Handler, return a valid exported name from Name()"],"exampleFix":"// before\nrouter.NewHandler(NewCalcService(\"\"))\n// after\nrouter.NewHandler(NewCalcService(\"Calculator\"))","handlingStrategy":"validation","validationCode":"if h.Name() == \"\" {\n\treturn errors.New(\"handler name must be non-empty before calling Handle\")\n}\nrouter.NewHandler(h)","typeGuard":null,"tryCatchPattern":"if err := router.NewHandler(h); err != nil {\n\tif strings.Contains(err.Error(), \"handler has no name\") {\n\t\treturn fmt.Errorf(\"handler %T missing configured name: %w\", h, err)\n\t}\n\treturn err\n}","preventionTips":["Validate handler name config at process startup, before wiring the router","Require name as a mandatory constructor/option parameter","Fail fast in tests: assert every handler's Name() is non-empty in a registration test"],"tags":["rpc","registration","configuration"],"backgroundTag":"rpc-handler-registration-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}