{"record":{"id":"d97e39f1bb28b7dd","repo":"inancgumus/learngo","slug":"record-domain-cannot-be-empty-record-page-cannot-b","errorCode":null,"errorMessage":"record.domain cannot be empty|record.page cannot be empty|record.visits cannot be negative|record.uniques cannot be negative","messagePattern":"record\\.domain cannot be empty\\|record\\.page cannot be empty\\|record\\.visits cannot be negative\\|record\\.uniques cannot be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"logparser/v6/logly/record/validate.go","lineNumber":29,"sourceCode":"import \"errors\"\n\n// validate whether the current record is valid or not.\nfunc (r *Record) validate() error {\n\tvar msg string\n\n\tswitch {\n\tcase r.Domain == \"\":\n\t\tmsg = \"record.domain cannot be empty\"\n\tcase r.Page == \"\":\n\t\tmsg = \"record.page cannot be empty\"\n\tcase r.Visits < 0:\n\t\tmsg = \"record.visits cannot be negative\"\n\tcase r.Uniques < 0:\n\t\tmsg = \"record.uniques cannot be negative\"\n\t}\n\n\tif msg != \"\" {\n\t\treturn errors.New(msg)\n\t}\n\treturn nil\n}\n","sourceCodeStart":11,"sourceCodeEnd":33,"githubUrl":"https://github.com/inancgumus/learngo/blob/3c475a78e54336c6255e925ff66b8ef4da6a2ae7/logparser/v6/logly/record/validate.go#L11-L33","documentation":"The v6 logly validate() checks Domain/Page emptiness and negative Visits/Uniques, returning a single error whose message is whichever rule failed. In v6 the caller (this error's combined message) aggregates all four possible messages, indicating one of the four record-validation rules failed during UnmarshalJSON or FromText.","triggerScenarios":"UnmarshalJSON or FromText receives a record that violates any rule: empty Domain, empty Page, negative Visits, or negative Uniques.","commonSituations":"Migrating v5 pipelines to v6 where old invalid data resurfaces; JSON feeds missing required keys; negative counters from diff-based ETL.","solutions":["Fix the offending record field indicated by the message (domain/page/visits/uniques).","Validate/normalize input JSON before calling UnmarshalJSON or FromText.","Use the typed record validation to pre-screen batches and skip invalid rows.","Update importers to fill defaults for missing domain/page and clamp negative counters."],"exampleFix":"// before\n{\"page\":\"/home\",\"visits\":-1}\n// after\n{\"domain\":\"example.com\",\"page\":\"/home\",\"visits\":0}","handlingStrategy":"validation","validationCode":"func validRecord(r logly.Record) bool {\n    return r.Domain != \"\" && r.Page != \"\" && r.Visits >= 0 && r.Uniques >= 0\n}\nif !validRecord(rec) { skipBatch() }","typeGuard":"func (r Record) IsValid() bool {\n    return r.Domain != \"\" && r.Page != \"\" && r.Visits >= 0 && r.Uniques >= 0\n}","tryCatchPattern":"err := rec.UnmarshalJSON(data)\nif err != nil {\n    var msg string\n    switch {\n    case strings.Contains(err.Error(), \"domain cannot be empty\"):\n        msg = \"missing domain\"\n    case strings.Contains(err.Error(), \"visits cannot be negative\"):\n        msg = \"negative visits\"\n    // ...\n    }\n    log.Printf(\"invalid record (%s): %s\", msg, data)\n}","preventionTips":["Pre-screen records with IsValid before unmarshaling","Fill defaults for missing domain/page in importers","Clamp negative counters at the ETL layer","Test migrations from v5 data for invalid 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"}