micro/go-micro · error

missing service instance name

Error message

missing service instance name

What it means

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.

Source

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

	// TODO(reddaly): Perform full validation.

	return nil
}

// 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 == "" {

View on GitHub (pinned to 24529f1404)

Solutions

  1. Pass a non-empty instance name, e.g. NewMDNSService("My App", "_http._tcp", "", "", port, ips, txt)
  2. Validate config/environment before registration and substitute a default name if empty
  3. In Register(), ensure the caller-provided instance is populated before constructing the service

Example fix

// before
svc, err := NewMDNSService(instance, "_http._tcp", "", "", 8080, ips, nil) // instance == ""
// after
if instance == "" {
	instance = filepath.Base(os.Args[0])
}
svc, err := NewMDNSService(instance, "_http._tcp", "", "", 8080, ips, nil)
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(instance) == "" {
	instance = filepath.Base(os.Args[0])
}
// safe to call NewMDNSService(instance, ...)

Type guard

func hasInstanceName(s string) bool { return strings.TrimSpace(s) != "" }

Try / catch

svc, err := NewMDNSService(instance, service, domain, hostName, port, ips, txt)
if err != nil {
	if strings.Contains(err.Error(), "missing service instance name") {
		return fmt.Errorf("service display name is required in configuration: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling NewMDNSService("", service, domain, hostName, port, ips, txt) — an empty instance argument, often from an unset config field or empty derived value.

Common situations: 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.

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/82abde45849c45f0. Report an issue: GitHub.