{"record":{"id":"956c49ba6fdaf77d","repo":"inancgumus/learngo","slug":"record-domain-cannot-be-empty","errorCode":null,"errorMessage":"record.domain cannot be empty","messagePattern":"record\\.domain cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"logparser/v5/pipe/record.go","lineNumber":96,"sourceCode":"func (r *record) MarshalJSON() ([]byte, error) {\n\trj := recordJSON{r.domain, r.page, r.visits, r.uniques}\n\treturn json.Marshal(rj)\n}\n\n// parseStr helps UnmarshalText for string to positive int parsing.\nfunc parseStr(name, v string) (int, error) {\n\tn, err := strconv.Atoi(v)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"Record.UnmarshalText %q: %v\", name, err)\n\t}\n\treturn n, nil\n}\n\n// validate whether a parsed record is valid or not.\nfunc validate(r record) (err error) {\n\tswitch {\n\tcase r.domain == \"\":\n\t\terr = errors.New(\"record.domain cannot be empty\")\n\tcase r.page == \"\":\n\t\terr = errors.New(\"record.page cannot be empty\")\n\tcase r.visits < 0:\n\t\terr = errors.New(\"record.visits cannot be negative\")\n\tcase r.uniques < 0:\n\t\terr = errors.New(\"record.uniques cannot be negative\")\n\t}\n\treturn\n}\n","sourceCodeStart":78,"sourceCodeEnd":106,"githubUrl":"https://github.com/inancgumus/learngo/blob/3c475a78e54336c6255e925ff66b8ef4da6a2ae7/logparser/v5/pipe/record.go#L78-L106","documentation":"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.","triggerScenarios":"Unmarshaling a text/JSON record where the domain field is missing, null, or set to \"\".","commonSituations":"A CSV/JSON row with a missing column; an upstream exporter omitting the domain key; whitespace-only values that were not trimmed.","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)."],"exampleFix":"// before\n{\"page\":\"/home\",\"visits\":10}\n// after\n{\"domain\":\"example.com\",\"page\":\"/home\",\"visits\":10}","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(rec.Domain) == \"\" {\n    return errors.New(\"record skipped: missing domain\")\n}\n_ = json.Unmarshal(data, &rec) // then rec.Validate()","typeGuard":"func hasDomain(r record) bool { return strings.TrimSpace(r.domain) != \"\" }","tryCatchPattern":"var rec record\nerr := rec.UnmarshalJSON(data)\nif err != nil {\n    if strings.Contains(err.Error(), \"record.domain cannot be empty\") {\n        log.Printf(\"dropping record without domain: %s\", data)\n        return nil\n    }\n    return err\n}","preventionTips":["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"],"tags":["validation","logparser","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"3c475a78e54336c6255e925ff66b8ef4da6a2ae7","analyzedAt":"2026-09-02T10:14:38.492Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}