inancgumus/learngo · error
record.domain cannot be empty
Error message
record.domain cannot be empty
What it means
validate() is called after UnmarshalText/UnmarshalJSON parse a record; it rejects records whose domain field is empty. The library treats domain as the mandatory primary key of a log record, so a record without one is invalid.
Source
Thrown at logparser/v5/pipe/record.go:96
func (r *record) MarshalJSON() ([]byte, error) {
rj := recordJSON{r.domain, r.page, r.visits, r.uniques}
return json.Marshal(rj)
}
// parseStr helps UnmarshalText for string to positive int parsing.
func parseStr(name, v string) (int, error) {
n, err := strconv.Atoi(v)
if err != nil {
return 0, fmt.Errorf("Record.UnmarshalText %q: %v", name, err)
}
return n, nil
}
// validate whether a parsed record is valid or not.
func validate(r record) (err error) {
switch {
case r.domain == "":
err = errors.New("record.domain cannot be empty")
case r.page == "":
err = errors.New("record.page cannot be empty")
case r.visits < 0:
err = errors.New("record.visits cannot be negative")
case r.uniques < 0:
err = errors.New("record.uniques cannot be negative")
}
return
}
View on GitHub (pinned to 3c475a78e5)
Solutions
- Ensure every input record includes a non-empty domain before unmarshaling.
- Trim and validate input columns; drop or repair rows missing the domain.
- Handle the error per-record and log/skip invalid rows.
- Add a schema check on the source data (e.g. require a domain column).
Example fix
// before
{"page":"/home","visits":10}
// after
{"domain":"example.com","page":"/home","visits":10} Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(rec.Domain) == "" {
return errors.New("record skipped: missing domain")
}
_ = json.Unmarshal(data, &rec) // then rec.Validate() Type guard
func hasDomain(r record) bool { return strings.TrimSpace(r.domain) != "" } Try / catch
var rec record
err := rec.UnmarshalJSON(data)
if err != nil {
if strings.Contains(err.Error(), "record.domain cannot be empty") {
log.Printf("dropping record without domain: %s", data)
return nil
}
return err
} Prevention
- Require a domain column in every export/feed
- Trim whitespace before unmarshaling
- Reject rows early at ingestion with clear logging
- Add round-trip tests covering missing-field records
When it happens
Trigger: Unmarshaling a text/JSON record where the domain field is missing, null, or set to "".
Common situations: A CSV/JSON row with a missing column; an upstream exporter omitting the domain key; whitespace-only values that were not trimmed.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- record.page cannot be empty
- record.domain cannot be empty|record.page cannot be empty|re
- invalid number
- record.visits cannot be negative
- record.uniques cannot be negative
AI-assisted analysis of inancgumus/learngo@3c475a78e5 (2026-09-02).
Data as JSON: /api/errors/956c49ba6fdaf77d.
Report an issue: GitHub.