netbirdio/netbird · error
record type is required
Error message
record type is required
What it means
Validate() returns this when Type is the empty string. FromAPIRequest copies req.Type (api.DNSRecordType, a string enum), so an omitted or blank "type" in DNSRecordRequest reaches it. The empty check runs before the per-type content switch.
Source
Thrown at management/internals/modules/zones/records/record.go:71
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
}
case RecordTypeCNAME:
if !domain.IsValidDomainNoWildcard(r.Content) {
return errors.New("invalid CNAME target format")
}
default:
return errors.New("invalid record type, must be A, AAAA, or CNAME")
}View on GitHub (pinned to 93e97f4bf1)
Solutions
- Set "type" to one of "A", "AAAA", or "CNAME" in the request.
- If building Record in Go, set r.Type = records.RecordTypeA (or AAAA/CNAME) before Validate().
- Make the client's type field required at the form/boundary layer so the request never leaves without it.
Example fix
// before
{"name": "api", "type": "", "content": "192.0.2.1"}
// after
{"name": "api", "type": "A", "content": "192.0.2.1"} Defensive patterns
Strategy: validation
Validate before calling
if req.Type == "" {
return fmt.Errorf("record type is required")
} Type guard
func hasRecordType(req *api.DNSRecordRequest) bool {
return string(req.Type) != ""
} Try / catch
if err := rec.Validate(); err != nil {
return respondBadRequest(err)
} Prevention
- Use a dropdown limited to A/AAAA/CNAME instead of free text for the type field.
- Fail client-side when type is empty rather than sending the request.
When it happens
Trigger: Record create/update body without a "type" key, or {"type": ""}; building a Record literal where Type is left as its zero value.
Common situations: A UI that defaults the type field to empty until a dropdown is touched; partial JSON merges that drop the type field; clients that send the type under a different key name.
Related errors
- record name is required
- zone name is required
- invalid record name format
- invalid CNAME target format
- invalid record type, must be A, AAAA, or CNAME
AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16).
Data as JSON: /api/errors/fa816c52db9be636.
Report an issue: GitHub.