micro/go-micro · error

missing service name

Error message

missing service name

What it means

NewMDNSService requires a non-empty service name — the DNS-SD service type such as "_http._tcp.". An empty service string fails the sanity check and the service cannot be registered.

Source

Thrown at internal/util/mdns/zone.go:70

}

// NewMDNSService returns a new instance of MDNSService.
//
// If domain, hostName, or ips is set to the zero value, then a default value
// will be inferred from the operating system.
//
// TODO(reddaly): This interface may need to change to account for "unique
// record" conflict rules of the mDNS protocol.  Upon startup, the server should
// check to ensure that the instance name does not conflict with other instance
// names, and, if required, select a new name.  There may also be conflicting
// hostName A/AAAA records.
func NewMDNSService(instance, service, domain, hostName string, port int, ips []net.IP, txt []string) (*MDNSService, error) {
	// Sanity check inputs
	if instance == "" {
		return nil, fmt.Errorf("missing service instance name")
	}
	if service == "" {
		return nil, fmt.Errorf("missing service name")
	}
	if port == 0 {
		return nil, fmt.Errorf("missing service port")
	}

	// Set default domain
	if domain == "" {
		domain = "local."
	}
	if err := validateFQDN(domain); err != nil {
		return nil, fmt.Errorf("domain %q is not a fully-qualified domain name: %v", domain, err)
	}

	// Get host information if no host is specified.
	if hostName == "" {
		var err error
		hostName, err = os.Hostname()
		if err != nil {

View on GitHub (pinned to 24529f1404)

Solutions

  1. Pass a valid DNS-SD service type, e.g. "_http._tcp."
  2. Default the service type in code if not configured: if service == "" { service = "_http._tcp." }
  3. Validate the service type against a known allowlist at startup

Example fix

// before
svc, err := NewMDNSService("myapp", serviceType, "", "", 8080, ips, nil) // serviceType == ""
// after
if serviceType == "" {
	serviceType = "_http._tcp."
}
svc, err := NewMDNSService("myapp", serviceType, "", "", 8080, ips, nil)
Defensive patterns

Strategy: validation

Validate before calling

var validServices = map[string]bool{"_http._tcp.": true, "_workstation._tcp.": true}
if !validServices[service] {
	return fmt.Errorf("unsupported or empty service type: %q", service)
}

Type guard

func isValidServiceType(s string) bool {
	return strings.HasPrefix(s, "_") && strings.Contains(s, "._")
}

Try / catch

svc, err := NewMDNSService(instance, service, domain, hostName, port, ips, txt)
if err != nil {
	if strings.Contains(err.Error(), "missing service name") {
		return fmt.Errorf("service type (e.g. \"_http._tcp.\") must be configured: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling NewMDNSService(instance, "", domain, hostName, port, ips, txt) with an empty service argument, e.g. a service-type variable that was never initialized in makeServiceWithServiceName or Register.

Common situations: Service type read from config where the key is missing; passing only the protocol ("_tcp") or a typo'd constant; refactors dropping the default "_workstation._tcp" value.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/8814a197e8f19002. Report an issue: GitHub.