netbirdio/netbird · error

record name is required

Error message

record name is required

What it means

Returned by records.Record.Validate() when the Name field is the empty string. A Record is populated from api.DNSRecordRequest via FromAPIRequest, so this surfaces when a DNS record create/update call omits or blanks the name. It is the first check in Validate, so it fires before format, type, and content checks.

Source

Thrown at management/internals/modules/zones/records/record.go:63

	return &api.DNSRecord{
		Id:      r.ID,
		Name:    r.Name,
		Type:    recordType,
		Content: r.Content,
		Ttl:     r.TTL,
	}
}

func (r *Record) FromAPIRequest(req *api.DNSRecordRequest) {
	r.Name = req.Name
	r.Type = RecordType(req.Type)
	r.Content = req.Content
	r.TTL = req.Ttl
}

func (r *Record) Validate() error {
	if r.Name == "" {
		return errors.New("record name is required")
	}

	if !domain.IsValidDomain(r.Name) {
		return errors.New("invalid record name format")
	}

	if r.Type == "" {
		return errors.New("record type is required")
	}

	switch r.Type {
	case RecordTypeA:
		if err := validateIPv4(r.Content); err != nil {
			return err
		}
	case RecordTypeAAAA:
		if err := validateIPv6(r.Content); err != nil {
			return err

View on GitHub (pinned to 93e97f4bf1)

Solutions

  1. Set the record name to a DNS label or FQDN (e.g. "api" or "api.example.com") in the request body.
  2. If constructing Record in Go, pass a non-empty name to NewRecord (or set r.Name) before calling Validate().
  3. Check the client sends the field the schema names exactly "name" (see api.DNSRecordRequest) so it is not silently dropped.

Example fix

// before
{"name": "", "type": "A", "content": "192.0.2.1", "ttl": 300}
// after
{"name": "api", "type": "A", "content": "192.0.2.1", "ttl": 300}
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(req.Name) == "" {
    return fmt.Errorf("record name is required")
}

Type guard

func hasRecordName(req *api.DNSRecordRequest) bool {
    return strings.TrimSpace(req.Name) != ""
}

Try / catch

if err := rec.Validate(); err != nil {
    return respondBadRequest(err) // map any Validate error to 400 with err.Error()
}

Prevention

When it happens

Trigger: POST/PATCH to a zone's records endpoint with body {"name":""} or with the name key missing; calling records.NewRecord(accountID, zoneID, "", ...) and then Validate(); a test fixture built without setting Name.

Common situations: A DNS record form submitted before the name field was filled; a client JSON key typo (e.g. "label" instead of "name") that decodes to the zero value; programmatic callers that set Content and Type but never Name.

Related errors


AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16). Data as JSON: /api/errors/655766588292b758. Report an issue: GitHub.