{"record":{"id":"82abde45849c45f0","repo":"micro/go-micro","slug":"missing-service-instance-name","errorCode":null,"errorMessage":"missing service instance name","messagePattern":"missing service instance name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/mdns/zone.go","lineNumber":67,"sourceCode":"\t// TODO(reddaly): Perform full validation.\n\n\treturn nil\n}\n\n// NewMDNSService returns a new instance of MDNSService.\n//\n// If domain, hostName, or ips is set to the zero value, then a default value\n// will be inferred from the operating system.\n//\n// TODO(reddaly): This interface may need to change to account for \"unique\n// record\" conflict rules of the mDNS protocol.  Upon startup, the server should\n// check to ensure that the instance name does not conflict with other instance\n// names, and, if required, select a new name.  There may also be conflicting\n// hostName A/AAAA records.\nfunc NewMDNSService(instance, service, domain, hostName string, port int, ips []net.IP, txt []string) (*MDNSService, error) {\n\t// Sanity check inputs\n\tif instance == \"\" {\n\t\treturn nil, fmt.Errorf(\"missing service instance name\")\n\t}\n\tif service == \"\" {\n\t\treturn nil, fmt.Errorf(\"missing service name\")\n\t}\n\tif port == 0 {\n\t\treturn nil, fmt.Errorf(\"missing service port\")\n\t}\n\n\t// Set default domain\n\tif domain == \"\" {\n\t\tdomain = \"local.\"\n\t}\n\tif err := validateFQDN(domain); err != nil {\n\t\treturn nil, fmt.Errorf(\"domain %q is not a fully-qualified domain name: %v\", domain, err)\n\t}\n\n\t// Get host information if no host is specified.\n\tif hostName == \"\" {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/internal/util/mdns/zone.go#L49-L85","documentation":"NewMDNSService requires a non-empty instance name — the human-readable service instance label advertised on the network (e.g. \"My Printer\"). An empty string fails the initial sanity checks and returns this error before any network setup.","triggerScenarios":"Calling NewMDNSService(\"\", service, domain, hostName, port, ips, txt) — an empty instance argument, often from an unset config field or empty derived value.","commonSituations":"Registering a service where the display name comes from an app config or environment variable that is unset; a generated name builder returning \"\" on failure.","solutions":["Pass a non-empty instance name, e.g. NewMDNSService(\"My App\", \"_http._tcp\", \"\", \"\", port, ips, txt)","Validate config/environment before registration and substitute a default name if empty","In Register(), ensure the caller-provided instance is populated before constructing the service"],"exampleFix":"// before\nsvc, err := NewMDNSService(instance, \"_http._tcp\", \"\", \"\", 8080, ips, nil) // instance == \"\"\n// after\nif instance == \"\" {\n\tinstance = filepath.Base(os.Args[0])\n}\nsvc, err := NewMDNSService(instance, \"_http._tcp\", \"\", \"\", 8080, ips, nil)","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(instance) == \"\" {\n\tinstance = filepath.Base(os.Args[0])\n}\n// safe to call NewMDNSService(instance, ...)","typeGuard":"func hasInstanceName(s string) bool { return strings.TrimSpace(s) != \"\" }","tryCatchPattern":"svc, err := NewMDNSService(instance, service, domain, hostName, port, ips, txt)\nif err != nil {\n\tif strings.Contains(err.Error(), \"missing service instance name\") {\n\t\treturn fmt.Errorf(\"service display name is required in configuration: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Make the service display name a required config field with startup validation","Default to a sensible name (executable name, product name) when unset","Fail at app start, not at registration time, when the name is blank"],"tags":["validation","mdns","configuration","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}