{"record":{"id":"bd8050fb72bbfbbd","repo":"inancgumus/learngo","slug":"record-uniques-cannot-be-negative","errorCode":null,"errorMessage":"record.uniques cannot be negative","messagePattern":"record\\.uniques cannot be negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"logparser/v5/pipe/record.go","lineNumber":102,"sourceCode":"func 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":84,"sourceCodeEnd":106,"githubUrl":"https://github.com/inancgumus/learngo/blob/3c475a78e54336c6255e925ff66b8ef4da6a2ae7/logparser/v5/pipe/record.go#L84-L106","documentation":"Sentinel validation error from the pipe package's internal validate() guard: a decoded record has a negative uniques value. It fires when the uniques column in JSON or text input is below zero; like visits, uniques is a count and must be non-negative, so validate() rejects the record.","triggerScenarios":"Unmarshaling a record where uniques < 0, e.g. \"uniques\": -2 in JSON or a negative text field in the uniques column.","commonSituations":"Same ETL/diff bugs as visits: subtracting counts, bad manual edits, or signed-column misparse during import.","solutions":["Clamp or fix negative uniques at the data source.","Audit upstream diff/aggregation logic for subtraction that can go negative.","Skip and log offending records during ingestion.","Relax the check only if negative uniques are valid in your pipeline."],"exampleFix":"// before\n{\"domain\":\"example.com\",\"page\":\"/\",\"uniques\":-1}\n// after\n{\"domain\":\"example.com\",\"page\":\"/\",\"uniques\":0}","handlingStrategy":"validation","validationCode":"if rec.Uniques < 0 {\n    rec.Uniques = 0 // clamp, or reject the record\n}","typeGuard":"func hasValidUniques(r record) bool { return r.uniques >= 0 }","tryCatchPattern":"var rec record\nerr := rec.UnmarshalJSON(data)\nif err != nil {\n    if strings.Contains(err.Error(), \"record.uniques cannot be negative\") {\n        log.Printf(\"dropping record with negative uniques: %s\", data)\n        return nil\n    }\n    return err\n}","preventionTips":["Clamp uniques at the source; never subtract counts below zero","Validate inputs before UnmarshalText/UnmarshalJSON","Monitor ingestion for negative-counter anomalies","Skip-and-log invalid rows rather than failing batches"],"tags":["validation","logparser","data-quality"],"backgroundTag":"schema-validation-failed","analyzedSha":"3c475a78e54336c6255e925ff66b8ef4da6a2ae7","analyzedAt":"2026-09-02T10:14:38.492Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}